How can access a file in the System directory, knowing the main directory, it's extension. But not knowing the name of the file and the nodes in between ( = Subderectories ) ?
-
1This seems like a strange request, what are you trying to achieve? – Matteo Italia Nov 04 '12 at 16:34
-
Is `boost::filesystem` an option? – Kos Nov 04 '12 at 16:34
2 Answers
How to find the contents of a directory, and hence find out what that file is named, differs from operating system to operating system. On Linux you would use diropen
, and something else on windows. However, the boost::filesystem library allows you to do this in a platform-independent way.
If I get what you are saying correctly, you are looking for a file "/System/foo/bar/baz.dat", but you don't know what "foo", "bar" or "baz" is. in that case, you will need to iterate through every file in every directory below "/System" until you find the one with the extension you are looking for.
See the top answer of this question for an example of such an iteration.
-
Using windows, but yes this is almost that exept that taking your example : "/System/foo/bar/baz.dat " I have /System/foo that gone always stay unchange .. – Alex Goncalves Nov 04 '12 at 17:33
You could do a search for all the files with that extension, starting from the System directory. Based on "System directory", I'm going to guess this is on Windows, in which case the functions you'd typically use for that search would be FindFirstFile
, FindNextFile
and FindClose
. You might also use SetCurrentDirectory
to traverse into the subdirectories under your starting point.
Based on what you've said (so far), it's hard to guess what you might want to do if you find more than one file with that extension.

- 476,176
- 80
- 629
- 1,111
-
Well those file are pushed from a system "A", i should treatment on them (done already), i have to find them based on them arrival on the system "B" . Sorry for the approximate English writing .. Anyway that's already a good answer to start with . Thaks a lot !!! – Alex Goncalves Nov 04 '12 at 17:03