I made a few changes and this should now display the files and folders in C:\. You will need to play around with the code to get the recursion effect that you want however.
PHP Code:
#include <iostream.h>
#include <fstream.h>
#include <string.h>
#include <windows.h>
bool FindFiles(char *pFiles,HANDLE handle);
int main(){
char *dir = "C:\\*.*";
HANDLE hFile=0;
FindFiles(dir,hFile);
return 0;
}
bool FindFiles(char *pFiles,HANDLE handle){
WIN32_FIND_DATA fData;
char buf[200],TmpPath[MAX_PATH],Buffer[MAX_PATH],*pBuffer;
pBuffer=Buffer;
if ((handle = FindFirstFile(pFiles,&fData))==INVALID_HANDLE_VALUE){
wsprintf (buf, "Error code %d", GetLastError() );
return 0;
}
while (FindNextFile(handle,&fData)!=0){
if((fData.dwFileAttributes==FILE_ATTRIBUTE_DIRECTORY)!=0 && strcmp(fData.cFileName,"..")){
GetCurrentDirectory(MAX_PATH,TmpPath);
FindFiles(strcat(TmpPath,"\\*.txt"),handle);
}
strcpy(Buffer,fData.cFileName);
cout << pBuffer << endl;
}
FindClose(handle);
return 0;
}




Reply With Quote