stdafx.h
#include <ImageHlp.h>
#pragma comment(lib,"imagehlp.lib")
//源文件中
//创建多级目录树
char* DirectoryType = "c:\\123\\123\\123\\"
MakeSureDirectoryPathExists(DirectoryType);
增加隐藏属性
CString str(DirectoryType);
SetFileAttributes(DirectoryType,FILE_ATTRIBUTE_HIDDEN);
//删除多级目录树
BOOL DeleteDirectory(char *DirName)
{
CFileFind tempFind;
char tempFileFind[200];
sprintf_s(tempFileFind,"%s\\*.*",DirName);
USES_CONVERSION;
BOOL IsFinded=(BOOL)tempFind.FindFile(A2T(tempFileFind));
while(IsFinded)
{
IsFinded=(BOOL)tempFind.FindNextFile();
if(!tempFind.IsDots())
{
char foundFileName[200];
// strcpy(foundFileName,tempFind.GetFileName().GetBuffer(200));
if(!WideCharToMultiByte(CP_ACP,0,tempFind.GetFileName(),-1,foundFileName,200,NULL,NULL))
{
return false;
}
if(tempFind.IsDirectory())
{
char tempDir[200];
sprintf_s(tempDir,"%s\\%s",DirName,foundFileName);
DeleteDirectory(tempDir);
}
else
{
char tempFileName[200];
sprintf_s(tempFileName,"%s\\%s",DirName,foundFileName);
DeleteFile(A2T(tempFileName));
}
}
}
tempFind.Close();
if(!RemoveDirectory(A2T(DirName)))
{
//MessageBox("删除目录失败!","警告信息",MB_OK);
return FALSE;
}
return TRUE;
}