遞迴遍歷檔案

2021-05-22 00:03:10 字數 1113 閱讀 3267

function enumfileinrecursion(path:pchar):longint;stdcall;

varsearchrec:tsearchrec;

found:integer;

tmpstr:string;

i:integer;

begin

i:=1;

result:=0; //查詢結果(檔案數)

//加上搜尋字尾,得到類似'c:/*.*' 、'c:/windows/*.*'的搜尋路徑

tmpstr:=strpas(path)+'/*.*';

//在當前目錄查詢第乙個檔案、子目錄

found:=findfirst(tmpstr,faanyfile,searchrec);

while found=0 do

//找到了乙個檔案或目錄後

begin

//如果找到的是個目錄

if (searchrec.attr and fadirectory)<>0 then

begin

if (searchrec.name <> '.') and (searchrec.name <> '..') then

begin

tmpstr:=strpas(path)+'/'+searchrec.name;

//自身呼叫,查詢子目錄,遞迴。。。。

result:=result+enumfileinrecursion(pchar(tmpstr));

end;

end//如果找到的是個檔案

else begin

//把找到的檔案加到memo控制項

arrfilename[i]:=strpas(path)+'/'+searchrec.name;

i:=i+1;

//filenum:=filenum+1;

//frmmain.memo1.lines.add(strpas(path)+'/'+searchrec.name);

end;

//查詢下乙個檔案或目錄

found:=findnext(searchrec);

end;

//釋放資源

findclose(searchrec);

end;

檔案的遞迴遍歷

遞迴 在函式中呼叫函式本身.就是遞迴 我們可以使用遞迴來遍歷各種樹形結構,比如我們的資料夾系統.可以使用遞迴來遍歷該資料夾中的所有檔案 import osdef read filepath,n files os.listdir filepath 獲取到當前資料夾中的所有檔案 for fi in fi...

遞迴遍歷目錄下的檔案

關於目錄檔案的分析 lib src vim lib,src,都是目錄檔案,而vim是普通檔案 opendir 返回乙個dir readdir dir 返回乙個dirent 結構的指標 struct dirent long d ino inode number 索引節點號 off t d off of...

使用遞迴遍歷資料夾

using system using system.data using system.configuration using system.collections using system.web using system.web.security using system.web.ui usin...