void FindFileInDir(char* rootDir, char* strRet){ char fname[MAC_FILENAMELENOPATH]; ZeroMemory(fname, MAC_FILENAMELENOPATH); WIN32_FIND_DATA fd; ZeroMemory(&fd, sizeof(WIN32_FIND_DATA)); HANDLE hSearch; char filePathName[256]; char tmpPath[256]; ZeroMemory(filePathName, 256); ZeroMemory(tmpPath, 256); strcpy(filePathName, rootDir); BOOL bSearchFinished = FALSE; if( filePathName[strlen(filePathName) -1] != '\\' ) { strcat(filePathName, "\\"); } strcat(filePathName, "*"); hSearch = FindFirstFile(filePathName, &fd); //Is directory if( (fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) && strcmp(fd.cFileName, ".") && strcmp(fd.cFileName, "..") ) { strcpy(tmpPath, rootDir); strcat(tmpPath, fd.cFileName); FindFileInDir(tmpPath, strRet); } else if( strcmp(fd.cFileName, ".") && strcmp(fd.cFileName, "..") ) { sprintf(fname, "%-50.50s", fd.cFileName); strcat(strRet + strRet[strlen(strRet)] , fname); } while( !bSearchFinished ) { if( FindNextFile(hSearch, &fd) ) { if( (fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) && strcmp(fd.cFileName, ".") && strcmp(fd.cFileName, "..") ) { strcpy(tmpPath, rootDir); strcat(tmpPath, fd.cFileName); FindFileInDir(tmpPath, strRet); } else if( strcmp(fd.cFileName, ".") && strcmp(fd.cFileName, "..") ) { sprintf(fname, "%-50.50s", fd.cFileName); strcat(strRet + strRet[strlen(strRet)] , fname); } } else { if( GetLastError() == ERROR_NO_MORE_FILES ) //Normal Finished { bSearchFinished = TRUE; } else bSearchFinished = TRUE; //Terminate Search } } FindClose(hSearch);}
引用第1楼惊羽九天于2007-10-04 21:35发表的 :用递归,API中的FindFirstFile和FindNextFile函数[code]void FindFileInDir(char* rootDir, char* strRet){ char fname[MAC_FILENAMELENOPATH]; ZeroMemory(fname, MAC_FILENAMELENOPATH);.......