0
点赞
收藏
分享

微信扫一扫

ClearDirectory 删除目录

witmy 2022-05-19 阅读 18


ClearDirectory(const char* szPath)

{


if( szPath == NULL )

return;

string strPath = szPath;

if( strPath.at(strPath.length()-1) != '\\' )

strPath.append("\\");

string strSearch = strPath+"*";

string strTarget;
WIN32_FIND_DATA FindFileData;

HANDLE hFind;

hFind = FindFirstFile(strSearch.c_str(), &FindFileData);

if (hFind == INVALID_HANDLE_VALUE)

{

DWORD dwErr = GetLastError();

return;

}

do

{

if( !(FindFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY ) )

{

strTarget = strPath+FindFileData.cFileName;

DeleteFile(strTarget.c_str());

}

else

{

if( 0 != strcmp(FindFileData.cFileName, ".") &&

0 != strcmp(FindFileData.cFileName, "..") )

{

strTarget = strPath+FindFileData.cFileName;

Linkwork::Win32::ClearDirectory(strTarget.c_str());

RemoveDirectory(strTarget.c_str());

}

}

} while( FindNextFile(hFind, &FindFileData) );

FindClose(hFind);


}
举报

相关推荐

0 条评论