VC删除文件夹(非空目录)及其中所有文件

 

BOOL CIOCPServer::DeleteDirectory(char* psDirName) { CFileFind tempFind; char sTempFileFind[ _MAX_PATH ] = { 0 }; sprintf(sTempFileFind,"%s//*.*",psDirName); BOOL IsFinded = tempFind.FindFile(sTempFileFind); while (IsFinded) { IsFinded = tempFind.FindNextFile(); if (!tempFind.IsDots()) { char sFoundFileName[ _MAX_PATH ] = { 0 }; strcpy(sFoundFileName,tempFind.GetFileName().GetBuffer(200)); if (tempFind.IsDirectory()) { char sTempDir[ _MAX_PATH ] = { 0 }; sprintf(sTempDir,"%s//%s",psDirName,sFoundFileName); DeleteDirectory(sTempDir); } else { char sTempFileName[ _MAX_PATH ] = { 0 }; sprintf(sTempFileName,"%s//%s",psDirName,sFoundFileName); DeleteFile(sTempFileName); } } } tempFind.Close(); if(!RemoveDirectory(psDirName)) { return FALSE; } return TRUE; }

 

方法二(直接调用命令):

#include< stdlib.h >
#include< stdio.h >

int main( )
{
system( "md d://aa//zhao " ); // 新建文件夹
system( "del   /s/q  d://aa//zhao " ); // 删除该文件夹下的所有文件
}

你可能感兴趣的:(MFC)