删除非空目录

发表于:2007-07-14来源:作者:点击数: 标签:
#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
#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");
}

原文转自:http://www.ltesting.net