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;
}
本文介绍了一个使用 C++ 实现的目录操作示例,包括如何创建多级目录树,并为目录设置隐藏属性,以及如何递归地删除整个目录树。该示例展示了 C++ 在文件系统操作方面的应用。

5276

被折叠的 条评论
为什么被折叠?



