typedef BOOL (*PROCESS_FILE_FUNCTION)(LPCTSTR filename);
上面的PROCESS_FILE_FUNCTION是一种函数指针,这个函数处理文件名为filename的文件,如果该函数返回
FALSE,则ProcessDirectory立刻退出,不再继续查找
void ProcessDirectory(LPCTSTR dirname,PROCESS_FILE_FUNCTION proc)
{
CStringArray dirs;
CString searchname;
CFileFind find;
dirs.Add(dirname);
BOOL bRet;
while(dirs.GetSize()>0)
{
searchname = dirs[0] +"//*.*";
dirs.RemoveAt(0);
bRet = find.FindFile (searchname,0);
if(!bRet)continue;
do{
bRet = find.FindNextFile ();
if(find.IsDots ())
{//忽略.和..文件
continue;
}
if(find.IsDirectory ())
{
dirs.Add (find.GetFilePath());
continue;
}else{
if(!proc(find.GetFilePath ()))
{
return;
}
}
}while(bRet);
}
}
上面的PROCESS_FILE_FUNCTION是一种函数指针,这个函数处理文件名为filename的文件,如果该函数返回
FALSE,则ProcessDirectory立刻退出,不再继续查找
void ProcessDirectory(LPCTSTR dirname,PROCESS_FILE_FUNCTION proc)
{
CStringArray dirs;
CString searchname;
CFileFind find;
dirs.Add(dirname);
BOOL bRet;
while(dirs.GetSize()>0)
{
searchname = dirs[0] +"//*.*";
dirs.RemoveAt(0);
bRet = find.FindFile (searchname,0);
if(!bRet)continue;
do{
bRet = find.FindNextFile ();
if(find.IsDots ())
{//忽略.和..文件
continue;
}
if(find.IsDirectory ())
{
dirs.Add (find.GetFilePath());
continue;
}else{
if(!proc(find.GetFilePath ()))
{
return;
}
}
}while(bRet);
}
}