files in a directory

Started by
3 comments, last by guyaton 18 years, 9 months ago
how do i get a list of files in a directory (windows) in c++ preferably not using MFC because this will be in a .dll file. i just want to see what files are there, look for certain extensions and possibly recurse through child directories. ~guyaton
~guyaton
Advertisement
I would use boost::filesystem.
Or if your laziness is of a form where you'd rather avoid having to get boost, and don't mind having to mess with the Win32 API, FindFirstFile(), FindNextFile(), and FindClose() will do the trick.
"We should have a great fewer disputes in the world if words were taken for what they are, the signs of our ideas only, and not for things themselves." - John Locke
Here is an example how to use it (not including error checking):
WIN32_FIND_DATA fd;//contains properties of the file
HANDLE hf = FindFirstFile (dirpath, &fd);//finds the first file in the directory
FindNextFile (hf, &fd)//find next file in directory
*The files that these functions retrieve can also be directories.
*FindNextFile returns NULL when there are no more files.
*The order which the files are retrieved is not sorted (at least i think so because when i used it i found no sorting, even the directories were mixed with the files, there weren't seperated to two groups).
Oh and by the way when using MFC you can include as a static linked library in the project settings and then you need to use no DLL.
thnx 4 ur help. those work nicely!

~guyaton
~guyaton

This topic is closed to new replies.

Advertisement