delphi获取目录下所有文件名
Posted 酷瑞
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了delphi获取目录下所有文件名相关的知识,希望对你有一定的参考价值。
delphi获取目录下所有文件名
procedure searchfile(path:string);//注意,path后面要有‘\‘;
var SearchRec:TSearchRec;
found:integer; begin found:=FindFirst(path+‘*.*‘,faAnyFile,SearchRec); while found=0 do begin if (SearchRec.Name<>‘.‘) and (SearchRec.Name<>‘..‘) and (SearchRec.Attr<>faDirectory) then ListBox1.Add(SearchRec.Name); found:=FindNext(SearchRec); end; FindClose(SearchRec); end;
上面一个只获取当前目录下所有文件,如果要获取该目录下的子目录的文件,看下面
procedure SearchFile(path:string); var SearchRec:TSearchRec; found:integer; begin found:=FindFirst(path+‘*.*‘,faAanyFile,SearchRec); while found=0 do
begin if (SearchRec.Name<>‘.‘) and (SearchRec.name<>‘..) and (SearchRec.Name=faDirectory) then SearchFile(SearchRec.Name+‘\‘) else LisBox1.Add(SearchRec.Name); found:=FindNext(SearchREc); end; FindClose(SearchRec);
end;
以上是关于delphi获取目录下所有文件名的主要内容,如果未能解决你的问题,请参考以下文章