Linux C遍歷資料夾

2021-10-09 21:35:47 字數 717 閱讀 4968

0x01:首先講一講遍歷資料夾必須要知道的乙個結構體struct dirent{};

struct dirent
0x2:具體用法見如下**query.c

#include

#include

intmain

(int argc,

char

**ar**)

pdir =

opendir

(ar**[1]

);if(

null

== pdir)

while(1

)else

}else

//沒有子檔案,跳出迴圈};

printf

("總檔案數為:%d\n"

, cnt)

;closedir

(pdir)

;return0;

}

效果如下:

curtis@curtis-virtual-machine:

~/desktop/query_dir$ .

/a.out /home/

name:[..

],不是普通檔案

name:[curtis]

,不是普通檔案

name:[.]

,不是普通檔案

總檔案數為:3

Linux C 刪除資料夾

方法一 include include include include include include define maxdir 256 char dirname maxdir rootdir maxdir void del dir char path while dirp readdir dp ...

遍歷資料夾

function search path string filename string ball boolean false string varsearchrec tsearchrec begin if findfirst path faanyfile,searchrec 0 then begin...

資料夾遍歷

c 遍歷指定資料夾中的所有檔案 directoryinfo thefolder new directoryinfo folderfullname 遍歷一層資料夾 foreach directoryinfo nextfolder in thefolder.getdirectories 遍歷多層資料夾 ...