欧美大屁股bbbbxxxx,狼人大香伊蕉国产www亚洲,男ji大巴进入女人的视频小说,男人把ji大巴放进女人免费视频,免费情侣作爱视频

歡迎來到入門教程網(wǎng)!

C語言

當(dāng)前位置:主頁 > 軟件編程 > C語言 >

C++遞歸刪除一個目錄實(shí)例

來源:本站原創(chuàng)|時間:2020-01-10|欄目:C語言|點(diǎn)擊: 次

本文實(shí)例講述了C++遞歸刪除一個目錄的實(shí)現(xiàn)方法。分享給大家供大家參考。具體方法如下:

CFindFile的使用框架如下:

復(fù)制代碼 代碼如下:
void Recurse(LPCTSTR pstr) 

   CFileFind finder; 
 
   // build a string with wildcards 
   CString strWildcard(pstr); 
   strWildcard += _T("\\*.*"); 
 
   // start working for files 
   BOOL bWorking = finder.FindFile(strWildcard); 
 
   while (bWorking) 
   { 
      bWorking = finder.FindNextFile(); 
 
      // skip . and .. files; otherwise, we'd 
      // recur infinitely! 
 
      if (finder.IsDots()) 
         continue; 
 
      // if it's a directory, recursively search it 
 
      if (finder.IsDirectory()) 
      { 
         CString str = finder.GetFilePath(); 
         TRACE(_T("%s\n"), (LPCTSTR)str); 
         Recurse(str); 
      } 
   } 
 
   finder.Close(); 
}

遞歸刪除代碼如下:

復(fù)制代碼 代碼如下:
//循環(huán)刪除一個目錄 
void RecursiveDelete(CString strDir) 

    CFileFind ff; 
    CString strPath; 
    strPath = strDir; 
    if (strPath.Right(1) != '\\') 
    { 
        strPath += '\\'; 
    } 
    strPath += "*.*"; 
 
    BOOL bWorking = ff.FindFile(strPath); 
    while (bWorking) 
    { 
        bWorking = ff.FindNextFile(); 
 
        // skip . and .. files; otherwise, we'd 
        // recur infinitely! 
        if (ff.IsDots()) 
            continue; 
 
        // if it's a directory, recursively search it 
 
        if (ff.IsDirectory()) 
        { 
            //遞歸目錄 
            CString str = ff.GetFilePath(); 
            TRACE(_T("%s\n"), (LPCTSTR)str); 
            RecursiveDelete(str); 
            //刪除目錄 
            ::SetFileAttributesA(str, FILE_ATTRIBUTE_NORMAL); 
            ::RemoveDirectory(str); 
        } 
        else 
        { 
            //刪除文件 
            CString str = ff.GetFilePath(); 
            TRACE(_T("%s\n"), (LPCTSTR)str); 
            ::SetFileAttributes(str, FILE_ATTRIBUTE_NORMAL); 
            ::DeleteFile(str); 
        } 
    } 
 
    ff.Close(); 
 

int main(int argc, char *argv[]) 

    RecursiveDelete("C:\\20_128\\"); 
    return 0; 
}

希望本文所述對大家的C++程序設(shè)計(jì)有所幫助。

上一篇:《C++ primer plus》讀書筆記(一)

欄    目:C語言

下一篇:《C++ primer plus》讀書筆記(三)

本文標(biāo)題:C++遞歸刪除一個目錄實(shí)例

本文地址:http://mengdiqiu.com.cn/a1/Cyuyan/3244.html

網(wǎng)頁制作CMS教程網(wǎng)絡(luò)編程軟件編程腳本語言數(shù)據(jù)庫服務(wù)器

如果侵犯了您的權(quán)利,請與我們聯(lián)系,我們將在24小時內(nèi)進(jìn)行處理、任何非本站因素導(dǎo)致的法律后果,本站均不負(fù)任何責(zé)任。

聯(lián)系QQ:835971066 | 郵箱:835971066#qq.com(#換成@)

Copyright © 2002-2020 腳本教程網(wǎng) 版權(quán)所有