I was wondering if there's an easy way in C++ to read a number of file names from a folder containing many files. They are all bitmaps if anyone is wondering.
I don't know much about windows programming so I was hoping it can be done using simple C++ methods.
Just had a quick look in my snippets directory. Found this:
This gives you a vector with all filenames in a directory. It only works on Windows of course.
João Augusto noted in an answer:
Don't forget to check after
FindClose(hFind)
for:It's especially important if scanning on a network.
Another alternative is -
system("dir | findstr \".bmp\" > temp.txt ");
I think you're looking for
FindFirstFile()
andFindNextFile()
.Why not use
glob()
?Boost provides a
basic_directory_iterator
which provides a C++ standard conforming input iterator which accesses the contents of a directory. If you can use Boost, then this is at least cross-platform code.C++17 includes a standard way of achieve that
http://en.cppreference.com/w/cpp/filesystem/directory_iterator
Possible output: