遞迴讀取指定目錄的檔案和資料夾,並統計檔案個數

2022-02-08 01:38:29 字數 1396 閱讀 4710

測試,遞迴讀取指定目錄的檔案和資料夾,在windowform程式的測試開發。

1.如果遞迴讀取檔案和資料夾

2.如果使用 func action 委託。(參考:

3.委託非同步處理資料,並獲取返回值

遇到錯誤就是 「執行緒間操作無效: 從不是建立控制項的執行緒訪問它」,使用空間提供的委託解決不再同一主線程的問題。

參考**如下。

view code

1

private

void button3_click(object sender, eventargs e)

2 78

public

void result(iasyncresult result)

9 );

19 label2.invoke(bb, string.format("

個檔案", aaa.endinvoke(result)));

20 }

21 }

22 }

2324

public

int getfilescount(string dirpath)

25 );

40 listbox1.invoke(bb, string.format("

", item.fullname));

41 }

42 }

43 totalfile += filelist.length;

4445

foreach (system.io.directoryinfo subdir in dirinfo.getdirectories())

46 );

53 listbox1.invoke(bb, string.format("

", subdir.fullname));

54 }

55 totalfile += getfilescount(subdir.fullname);

56 }

57 }

58catch (exception)

59

61return totalfile;

62 }

自己測試參考,學習之用.如有不對地方,請包涵.

linux 平台遞迴讀取讀取所有資料夾和檔名稱

include include include include include include include define max 1024 char path 100 char strmin char des,const char min return des void print char p...

Qt遞迴遍歷檔案和資料夾

遞迴遍歷資料夾,找到所有的檔案 filepath 要遍歷的資料夾的檔名 int findfile const qstring filepath 取到所有的檔案和檔名,但是去掉.和.的資料夾 這是qt預設有的 dir.setfilter qdir dirs qdir files qdir nodota...

怎樣cp資料夾時忽略指定的資料夾和檔案

在備份ltedecoder程式時,須要把此資料夾拷由到bak資料夾下。但decoder資料夾下有個大檔案,不須要備份,還有日誌問題,也不須要備份,怎樣實現呢?方法 cd source dir find name snapshot prune o print0 cpio pmd0 dest dir 此...