C++递归之获取文件列表
时间:2011-05-29 来源:Eslizn
递归是个好东西啊
#include <iostream> #include <windows.h> #include <string> using namespace std; char* str_add(char* a, char* b); void EchoFiles(TCHAR* path,TCHAR* type); int main() { TCHAR* path; TCHAR* type = "*"; char input[MAX_PATH]; cout << " Input Path:"; cin >> input; cout << "\n You Input Path Is:" << input << endl; path = str_add(input,""); //cout << path << endl; EchoFiles(path,type); return 0; } char* str_add(char* a, char* b) { char* t = new char[strlen(a) + strlen(b) + 1]; static char* tmp; sprintf(t,"%s%s",a,b); tmp = t; return tmp; } void EchoFiles(TCHAR* path,TCHAR* type) { WIN32_FIND_DATA fInfo; HANDLE hFile; hFile = FindFirstFile(str_add(path,type),&fInfo); while(hFile != INVALID_HANDLE_VALUE) { if(fInfo.dwFileAttributes == 16) { if(strcmp(fInfo.cFileName,".") != 0 && strcmp(fInfo.cFileName,"..") != 0) { TCHAR* tp = str_add(path,fInfo.cFileName); EchoFiles(str_add(tp,"\\"),type); } } else { cout << str_add(path,fInfo.cFileName) << endl; } if(FindNextFile(hFile,&fInfo) == 0) { break; } } FindClose(hFile); }
GetFileLits.zip
相关阅读 更多 +
排行榜 更多 +