Hi,
I have been experiment with Recursion / Trasversal through directories recently but seem to have run into a few unexplainable errors. Attached is my source code which is a function (which has the path (input user directory) passed into it).
What im hoping this function will do is detect if inside this directory (path) are subdirectories and if so store these in an array (creating a list of subdirectories) allowing a following function to open these inorder and run a process on all files inside.
Any ideas what im doing wrong? I've look across various forums etc at FindNextFile(), FindNext() functions etc but have been unable to get my head around them.
Many thanks;
void DirectoryCheck(char path[50])
{
int dirno2; //used to count directories once i get the function working
dirno2 = 0;
chdir (path);
printf (path);
char directories[15][50];
//void EmptyDirectory(char* folderPath)
char fileFound[256];
WIN32_FIND_DATA info;
HANDLE hp;
printf(fileFound, " %s\\*.*", path);
hp = FindFirstFile(fileFound, &info);
printf("\n");
do
{
if (!((strcmp(info.cFileName, ".")==0)||
(strcmp(info.cFileName, "..")==0)))
{
if((info.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)== 0)
{
printf("Sub Directory File Found : ");
printf(fileFound,"%s\\%s", path, info.cFileName);
printf("done top\n");
}
else
{
printf("Text File Found : ");
printf("%s\\%s", folderPath, info.cFileName);
}
}
}while(FindNextFile(hp, &info));
FindClose(hp);
}