//Editor's note:
//COTD Entry: File Enumerator by Sam McGrath [sammy@dnai.com]
void System_Dir(const char *directory, bool recurse,
void(*dirCallback)(const char *dir),
void(*fileCallback)(const char *filename))
{
WIN32_FIND_DATA finddata;
HANDLE handle;
handle = FindFirstFile(directory, &finddata);
if (handle == INVALID_HANDLE_VALUE)
return;
do
{
if (!(finddata.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN) &&
!(finddata.dwFileAttributes & FILE_ATTRIBUTE_SYSTEM) &&
!(finddata.dwFileAttributes & FILE_ATTRIBUTE_TEMPORARY))
{
if (finddata.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
{
if (strcmp(finddata.cFileName, ".") && strcmp(finddata.cFileName, ".."))
if (dirCallback)
dirCallback(finddata.cFileName);
}
else
{
if (fileCallback)
fileCallback(finddata.cFileName);
}
}
} while (FindNextFile(handle, &finddata));
FindClose(handle);
} |