C 遍歷指定資料夾 相應操作

2021-07-25 05:31:34 字數 714 閱讀 5465

在平時開發中,時常需要遍歷指定資料夾目錄下的所有檔案,在這裡總結一下**。

下面這段**就是遞迴遍歷指定目錄,把遍歷出來檔案資訊儲存到vector向量裡面:

bool filetra(cstring &strdir,vector&file)

cfilefind filefind;

bool bfound = filefind.findfile(strdir + _t("\\*"), 0);

while (bfound)

else

}}

除了獲取資訊,也可以做別的操作,如遞迴遍歷刪除指定資料夾,這個也是比較常用的,**如下:

//遍歷刪除指定目錄下所有資料夾以及檔案

void deletedirectory(cstring strdir)

//首先刪除檔案及子資料夾

cfilefind ff;

bool bfound = ff.findfile(strdir+ _t("\\*"),0);

while(bfound)

else

} ff.close();

//如果有需要連這個資料夾都刪除,可以把這一句注釋去掉

//removedirectory(strdir);

}

總體流程還是沒什麼變化的,主要就是遍歷指定目錄,然後做相應操作即可。

c 遍歷資料夾深度 C 遍歷資料夾獲取資料夾大小

c 遍歷資料夾獲取資料夾大小 都需要引入system.io這個命名空間 第一種方法 public static long getdirectorylength string dirpath 判斷給定的路徑是否存在,如果不存在則退出 if directory.exists dirpath return...

C 遍歷資料夾

下面是一段用於遍歷資料夾內的指定型別檔案的程式 c 遍歷資料夾 author www.icvpr.com blog include include include using namespace std int main int argc,char argv 2.迴圈查詢 do sprintf fi...

c 遍歷資料夾

link 編寫程式遍歷資料夾及其子資料夾下所有檔案,並輸出到標準輸出流或者檔案流。1.先考慮在單層目錄下,遍歷所有檔案。以c windows為例 用到資料結構 finddata t,檔案資訊結構體的指標。c struct finddata t 檔案屬性是無符號整數,取值為相應的巨集 a arch 存...