MFC删除文件及其所有子目录子文件

 

bool DeleteDirectory(const CString& strDirName)
{
    CFileFind tempFind;
    TCHAR sTempFileFind[200];
    _tcscpy(sTempFileFind, strDirName);
    _tcscat(sTempFileFind, L"\\*.*");
    BOOL IsFinded = tempFind.FindFile(sTempFileFind);
    while (IsFinded)
    {
        IsFinded = tempFind.FindNextFile();

        TCHAR sFoundFileName[200];
        _tcscpy(sFoundFileName, tempFind.GetFilePath());
        DeleteFile(sFoundFileName);
    }
    tempFind.Close();
    if (!RemoveDirectory(strDirName))
    {
        return FALSE;
    }
    return TRUE;
}

 

posted @ 2020-04-08 11:52  余生以学  阅读(784)  评论(0编辑  收藏  举报