文件搜索只能在c盘运行啊?
在运用cfilefind类的findfile,findnextfile函数进行递归遍历指定目录,
从而检索出指定的文件。
奇怪的是:无论我是执行还是调试它,都只能在C盘下搜索,而且还只能是.txt,.log等文本文件
对于.exe,.dll等,出错,调试也如此。
在其他盘,搜索不完整。
以下是dll中的搜索实现函数(mfc中加载它):
void FindFile( CString path)
{
BOOL FileBool;
CFileFind f;
char fpath[256]="";
_chdir(path);
FileBool= f.FindFile(file_name);
while(FileBool)
{
FileBool=f.FindNextFile();
if (!f.IsDirectory())
{
file_num++;
sprintf(fpath,"%s",f.GetFilePath());
strcat(RecordBuff,fpath);
strcat(RecordBuff,"\r\n");
}
} f.Close();
return;
}
void FindDirectory( CString fpath)
{
if (strlen(RecordBuff)>=100)
{
SaveRecod.open("c:\\dd.txt",ios::out|ios::app|ios::binary);
SaveRecod.write(RecordBuff, strlen(RecordBuff));
SaveRecod.close();
memset(RecordBuff,'\0',356);
}
FindFile(fpath);
BOOL b;
CFileFind f;
b = f.FindFile("*.*");
while(b)
{
b=f.FindNextFile();
if (f.IsDirectory())
{
//当前文件是目录
if (!f.IsDots())
{
FindDirectory(f.GetFilePath());
}
}
}
f.Close();
}
dllmain函数就是执行finddirection()函数,哦,这里没有为它单独创建线程!
这个递归算法应该没什么问题吧??