//遍历目录内所有子目录及子目录中的文件,Flag=0仅列举,Flag=1仅删除文件,Flag=2删除所有文件及所有子目录 ListAllFile( Dir+sr.Name+"//",Flag,List );//递归查找并处理子目录中所有文件 FindClose(sr); |
///
jishiping前辈给我的查找函数,你可以参考改进一下
void SearchFile(LPCSTR path, TStringList* List)
{
char *s;
char File[512];
HANDLE hFind;
WIN32_FIND_DATA fd;
strcpy(File, path);
s = File + strlen(File);
if (*(s-1) != '// ')
*s++ = '// ';
strcpy(s, "*.txt ");//你把这个 *.txt用*.*替换可以搜索全部文件
hFind = FindFirstFile(File, &fd);
if (hFind==INVALID_HANDLE_VALUE)
return;
do {
strcpy(s, fd.cFileName);
if (fd.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY) {
//添加对文件夹的处理
if (*s != '. ') //忽略 ". " 和 ".. "
SearchFile(File);
}
else { //文件
List-> Add(File);
}
}while(FindNextFile(hFind,&fd));
FindClose(hFind);
}