|
-
Jan 28th, 2002, 06:09 PM
#1
Thread Starter
Member
Recursive directory search
Subject: Recursive directory listing using FindFirstFile,FindNextFile etc
O.S: w2000 pro
Compiler VC++ 6
App: console
Hello
Trying to write a recursive function (my first) to search directories for files that meet a criteria. I’m nearly there ,but I can’t get the function to list the content of a directory when it find one. I have been staring at this problem for hours but I can’t see the flaw.
A nugde in the right direction would be gratefully apprepricated
Regards
Hmm 
The code:
#include <iostream>
#include <fstream.h>
#include <windows.h>
#include <string.h>
using namespace std;
bool FindFiles(char *pFiles,HANDLE handle);
int main(){
char *dir = "C:\*";
HANDLE hFile;
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);
std::cout << pBuffer << std::endl;
}
FindClose(handle);
return 0;
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|