//find first file while(IsFinded) { IsFinded=(BOOL)tempFind.FindNextFile(); //research the next file in recursion if(!tempFind.IsDots()) //if is not "." directory { char foundFileName[200]; strcpy(foundFileName,tempFind.GetFileName().GetBuffer(200)); if(tempFind.IsDirectory()) //if it is directory,then do recursion { //DeleteDirectory char tempDir[200]; sprintf(tempDir,"%s\\%s",DirName,foundFileName); //目录名 ListDirAndFile(tempDir); //递归 } else { //if it is file,then delete char tempFileName[200]; sprintf(tempFileName,"%s\\%s",DirName,foundFileName);//文件名 } } } tempFind.Close(); return TRUE; }
{
ListDirAndFile("C:\\AAa\\");
}BOOL CTtDlg::ListDirAndFile(LPCTSTR DirName)
{
CFileFind tempFind;
char tempFileFind[200] ={0};
sprintf(tempFileFind,"%s\\*.*",DirName);
BOOL IsFinded=(BOOL)tempFind.FindFile(tempFileFind);
//find first file
while(IsFinded)
{
IsFinded=(BOOL)tempFind.FindNextFile(); //research the next file in recursion
if(!tempFind.IsDots()) //if is not "." directory
{
char foundFileName[200];
strcpy(foundFileName,tempFind.GetFileName().GetBuffer(200));
if(tempFind.IsDirectory()) //if it is directory,then do recursion
{
//DeleteDirectory
char tempDir[200];
sprintf(tempDir,"%s\\%s",DirName,foundFileName); //目录名
ListDirAndFile(tempDir); //递归
}
else
{
//if it is file,then delete
char tempFileName[200];
sprintf(tempFileName,"%s\\%s",DirName,foundFileName);//文件名
}
}
}
tempFind.Close();
return TRUE;
}
BOOL bWorking = finder.FindFile("C:\\*.*");
while (bWorking)
{
bWorking = finder.FindNextFile();
std::cout << (LPCTSTR) finder.GetFileName() << std::endl;
}