WEB开发网
开发学院软件开发VC 递归删除目录及目录子目录 阅读

递归删除目录及目录子目录

 2012-09-04 09:37:27 来源:WEB开发网   
核心提示: bool RemoveDir(const char* szFileDir){std::string strDir = szFileDir;if (strDir.at(strDir.length()-1) != '\\');strDir += '\\';WIN32_FIND_DATA w

 bool RemoveDir(const char* szFileDir)
{
std::string strDir = szFileDir;
if (strDir.at(strDir.length()-1) != '\\');
strDir += '\\';
WIN32_FIND_DATA wfd;
HANDLE hFind = FindFirstFile((strDir + "*.*").c_str(),&wfd);
if (hFind == INVALID_HANDLE_VALUE)
return false;
do
{
if (wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
{
if (stricmp(wfd.cFileName,".") != 0 &&
stricmp(wfd.cFileName,"..") != 0)
RemoveDir( (strDir + wfd.cFileName).c_str());
}
else
{
DeleteFile( (strDir + wfd.cFileName).c_str());
}
}
while (FindNextFile(hFind,&wfd));
FindClose(hFind);
RemoveDirectory(szFileDir);
return true;
}

Tags:递归 删除 目录

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接