How to get all files in a given directory using C++ on windows?
Note:
I found methods that use dirent.h
but I need a more standard way...
Thanks
A directory is a unique type of file that contains only the information needed to access files or other directories. As a result, a directory occupies less space than other types of files. File systems consist of groups of directories and the files within the directories.
The directory is a place/area/location where a set of the file(s) will be stored. Subdirectory is a directory inside the root directory, in turn, it can have another sub-directory in it. In C programming language you can list all files and sub-directories of a directory easily.
Use FindFirstFile and related functions. Example:
HANDLE hFind;
WIN32_FIND_DATA data;
hFind = FindFirstFile("c:\\*.*", &data);
if (hFind != INVALID_HANDLE_VALUE) {
do {
printf("%s\n", data.cFileName);
} while (FindNextFile(hFind, &data));
FindClose(hFind);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With