请问MFC中有没有搜索本机文件的函数呀?(100分)

  • 主题发起人 sands510
  • 开始时间
S

sands510

Unregistered / Unconfirmed
GUEST, unregistred user!
哪位大哥知道请帮帮忙,小弟急用:),如果没有提供给我一个编好的搜索本机文件的函数也可以,小弟在这里谢过了。
 
MFC中CFileFind类良好地封装了FindNextFile、FindFirstFile等API函数。
您可以方便地调用它,来查找文件。
下面这个函数可以删除某个目录,但不能是当前使用的目录。
原因在于Windows不允许当前工作目录被删除。
BOOL DeleteDirectory(char *DirName)
{
CFileFind tempFind;
char tempFileFind[200];
sprintf(tempFileFind,"%s//*.*",DirName);
BOOL IsFinded=(BOOL)tempFind.FindFile(tempFileFind);
while(IsFinded)
{
IsFinded=(BOOL)tempFind.FindNextFile();
if(!tempFind.IsDots())
{
char foundFileName[200];
strcpy(foundFileName,tempFind.GetFileName().GetBuffer(200));
if(tempFind.IsDirectory())
{
char tempDir[200];
sprintf(tempDir,"%s//%s",DirName,foundFileName);
DeleteDirectory(tempDir);
}
else
{
char tempFileName[200];
sprintf(tempFileName,"%s//%s",DirName,foundFileName);
DeleteFile(tempFileName);
}
}
}
tempFind.Close();
if(!RemoveDirectory(DirName))
{
MessageBox(0,"删除目录失败!","警告信息",MB_OK);
return FALSE;
}
return TRUE;
}
 
顶部