I have a directory that should contain one file. it has an extension of .png but the name is semi-random. I've tried a dozen tutorials for using boost to get the filename but they all exit the console with no error. what is the simplest function to use boost to get this file name?
Asked
Active
Viewed 225 times
0
-
_'I've tried a dozen tutorials for using boost to get the filename'_ Could you be a bit more specific, may be on one of your trials' problems. As it is it's pretty unclear what you're asking for?!? There's [`boost::file::exists()`](http://stackoverflow.com/questions/268023/whats-the-best-way-to-check-if-a-file-exists-in-c-cross-platform), if it's what you're after. – πάντα ῥεῖ Feb 09 '14 at 22:24
-
im asking that for a path. lets say fs::path mypath = "C:\\test\\"; return the name of the only file in that directory – Aaron Feb 09 '14 at 22:29
-
`boost::path` and [wildcard search](http://stackoverflow.com/questions/1257721/can-i-use-a-mask-to-iterate-files-in-a-directory-with-boost)? I'm afraid from this reference it's not possible like that. But you could of course use regex to parse for any listed filenames from a path. – πάντα ῥεῖ Feb 09 '14 at 22:30
-
doesnt work. boost:filesystem:directory_entry has no member leaf – Aaron Feb 09 '14 at 22:44
-
If your directory contains only one file, can't you produce a list of all files in that directory. Then the only file that is there must be the one you want. – Brandin Feb 09 '14 at 22:49
-
of course, but how do i get that only one? – Aaron Feb 09 '14 at 22:51
1 Answers
0
To access the file/directory names placed n a particular boost::path
instance you have, use boosts directory_iterator
, as shown in the linked example.
To check for particular file-/directory name signatures found from iterating, boost::regex
might come in handy.

πάντα ῥεῖ
- 1
- 13
- 116
- 190
-
error identifier is_directory is undefined. directory_iterator is undefined same for is_regular, file_size and exists – Aaron Feb 09 '14 at 22:57
-
Are you sure to have the referenced boost version installed and made up all `-I`, `-L`, `-l
` options setup correctly? Not to mention namespace references? **EDIT:** Sorry, I gave the wrong link for `directory_iterator`, check again ... – πάντα ῥεῖ Feb 09 '14 at 23:01 -