i want to print every file of my PC
but this code is not searching subfolder(depth value is 2)
besides how can i search all drives(C:\,D:\......)one after one using this code...??
Code:
#include <stdarg.h>
#include <stdio.h>
#include <windows.h>
#include <string.h>
void Find(char *Path)
{
char tmpPath[MAX_PATH];
char subPath[MAX_PATH];
strcpy(tmpPath, Path);
strcat(tmpPath, "\*");
WIN32_FIND_DATA FindData;
HANDLE hFind = FindFirstFile(tmpPath,&FindData);
if(hFind == INVALID_HANDLE_VALUE)
return;
do
{
if(FindData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY && strcmp(FindData.cFileName , ".")!=0 && strcmp(FindData.cFileName , "..")!=0)
{
printf("%s\n", FindData.cFileName);
subPath[strlen(Path) + strlen(FindData.cFileName) + 2];
strcpy(subPath, Path);
strcat(subPath, FindData.cFileName);
strcat(subPath, "\\");
strcat(subPath,"*.*");
Find(subPath);
}
else
printf(" %s\n",FindData.cFileName);
}while(FindNextFile(hFind,&FindData));
FindClose(hFind);
}
int main()
{
Find("C:\\");
}