Feb 12
18
List Files Folders in a Directory in C++ Windows
Leave a comment »
Below is an example of how to loop over all files and folders in a given location and output the names.
#include <Windows.h>
int main(int argc, char** argv)
{
HANDLE hFind = INVALID_HANDLE_VALUE;
WIN32_FIND_DATA ffd;
hFind = FindFirstFile(TEXT("C:\\temp\\*"), &ffd);
do
{
Sleep(1000);
bool isDirectory = ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY;
if(isDirectory)
{
cout << "DirectoryName: " << ffd.cFileName << endl;
}
else
{
cout << "FileName: " << ffd.cFileName << endl;
}
}while(FindNextFile(hFind, &ffd) != 0);
FindClose(hFind);
}
http://msdn.microsoft.com/en-us/library/windows/desktop/aa365200(v=vs.85).aspx
Tweet