VS 2008 創建、刪除多級目錄的方法 以及給文件夾增加隱藏屬性

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;
}


發佈了27 篇原創文章 · 獲贊 12 · 訪問量 21萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章