敬业的IT人 >> 编程开发 >> Visual C++/MFC >> 删除非空目录

删除非空目录

敬业的IT人 互联网 佚名 2008-1-4 18:58:45
#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");
}

粤ICP备06119539号
Copyright CiscoSky.Org,Some Rights Reserved.
Email:me1228#tom.com