删除非空目录
【打印文章】
#include "stdafx.h"
bool DeleteDirectory(char* DirName)
{
CFileFind tempFind;
char tempFileFind[200] ;
sprintf(tempFileFind,"%s\\*.*",DirName);
BOOL IsFinded = tempFind.FindFile(tempFileFind);
while (IsFinded)
{
IsFinded = 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,"é?3y꧰ü","꧰ü",MB_OK);
return FALSE;
}
return TRUE;
}
void main()
{
DeleteDirectory("d:\\222");
}
bool DeleteDirectory(char* DirName)
{
CFileFind tempFind;
char tempFileFind[200] ;
sprintf(tempFileFind,"%s\\*.*",DirName);
BOOL IsFinded = tempFind.FindFile(tempFileFind);
while (IsFinded)
{
IsFinded = 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,"é?3y꧰ü","꧰ü",MB_OK);
return FALSE;
}
return TRUE;
}
void main()
{
DeleteDirectory("d:\\222");
}
本栏文章均来自于互联网,版权归原作者和各发布网站所有,本站收集这些文章仅供学习参考之用。任何人都不能将这些文章用于商业或者其他目的。( Pfan.cn )
【编程爱好者论坛】