Originally Posted by
Salem
There's a tree walker in the FAQ.
Perhaps start there.
Directory recursion is very easy...
Code:
//This is the only Directory Structure Used
WIN32_FIND_DATA DirData;
//Temporary buffer for path names
char FPath[MAX_PATH];
// recursive directory search
void WalkDirs(PCHAR SPath)
{ HANDLE HDir;
// switch to specified direcory
if (!SetCurrentDirectory(SPath))
{ printf("Error Invalid Pathname\n");
exit(GetLastError()); }
// Show Full Pathname
GetCurrentDirectory(MAX_PATH,FPath);
printf("--> %s\n",FPath);
// begin directory scan
HDir = FindFirstFile("*.*",&DirData);
do
{ if (DirData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
{ // ignore . and .. sillyness
if ((strcmp(DirData.cFileName,".") != 0) &&
(strcmp(DirData.cFileName,"..") != 0))
{ // call myself to test a new directory
WalkDirs(DirData.cFileName);
// done, now back up one level
SetCurrentDirectory("..");
// Show Pathname
GetCurrentDirectory(MAX_PATH,FPath);
printf("<-- %s\n",FPath); } }
else
// list filenames
printf("\t\t%s\n",DirData.cFileName);
while (FindNextFile(HDir,&DirData) != ERROR_NO_MORE_FILES);
FindClose(HDir); }