boost遞迴遍歷獲得特定目錄下的所有資料夾名

2021-08-15 06:07:22 字數 894 閱讀 4171

在windows作業系統下可以使用微軟的檔案查詢功能_findfirst(或_findfirsti64) 和_findnext(或者_findnexti64)配合_finddata_t(或者_finddatai64_t),但是無法脫離windows使用。

如果需要使用寬字元的查詢,可以在下劃線後加入w(如_wfindfirst)。

使用boost的filesystem可以擺脫系統關聯,so,查詢檔案夾的**如下。

#include 

#include

#include

using

namespace boost::filesystem;

void getfolders(std::vector

& folders, const

wchar_t * folders_path)

getfolders(folders, dir_wname.c_str());}}

}else

}catch (const filesystem_error& ex)

}void main()

std::system("pause");

}

如果需要查詢檔案名可以使用函式:

bool boost:

:filesystem

::is_regular_file(boost:

:filesystem

::path &p);

替代資料夾查詢:

bool boost:

:filesystem

::is_directory(boost:

:filesystem

::path &p);

遞迴遍歷目錄

遞迴 乙個函式內部在其內部不呼叫其他函式,而是呼叫自身,類似迴圈 注,自己玩自己,防止死遞迴 使用遞迴來遍歷出乙個目錄中的所有檔案 import os def getalldirre path,sp 引數 路徑 返回值 none 完成功能,獲取呼叫者傳遞的路徑下的所有檔案 檔案 直接顯示,資料夾 二...

windows 遍歷 特定目錄下檔案

參考自 很多類似 都有 wchar char 等型別問題 s 問題。一下 在 windows10 vs2017上親測可用 cmd test.cpp 定義控制台應用程式的入口點。include stdafx.h include include include include using namespa...

Qt 遞迴方式遍歷目錄

基本思想 1.指定乙個目錄 2.找到當前目錄下的檔案 不包括資料夾,qdir可以進行篩選 存入qfileinfolist,然後按順序存入qtreewidgetitem,並新增至根節點 3.找到當前目錄下的第乙個資料夾,作為乙個新的根節點 4.重複2,3過程,直到沒有新的資料夾 至此遞迴過程完畢。qf...