ClearDirectory 删除目录

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

原文地址:https://www.cnblogs.com/ahuo/p/1409474.html