Originally posted by kalavathy
how do i get the file names of all the files in a folder / directory in c++?
There are no standard C++ functions to get the names of the files in a directory. You need to tell us the operating system and compiler you are using, since getting the names of the files all depend on compiler and OS.
If you want a cross-platform solution, you can investigate the boost libraries at www.boost.org. They have a file/directory class that works on various operating systems.
In addition to Paul's correct answer...if you are using Windows, take a look at the following FAQ. It shows how one can do it in Windows, however, it basically can be easily ported to a different operating system/compiler since the way is still the same (except for the keywords probably)...
Ciao, Andreas
"Software is like sex, it's better when it's free." - Linus Torvalds
Originally posted by Ejaz
Although the code in the link that u mention is quite perfect, but I saw another thread, which mentioned a minor bug in it...
Well...I would not consider this as a bug since I am still of the opinion that filenames like "this.is.my.file.txt" are invalid.
Anyway, this can be solved by using the 'rfind()' function instead of 'find()'. Since I do not want to start a discussion about whether these names are invalid or not, I simply changed the appropriate FAQs...
Ciao, Andreas
"Software is like sex, it's better when it's free." - Linus Torvalds
Bookmarks