files in a directory
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
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.
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.
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.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement