本文来自http://blog.youkuaiyun.com/hellogv/
procedure TSysClass.FindAll(path: String; var fileresult: TStrings);//查找文件 ,path不带'/'
var
fpath,s: String;
fs: TsearchRec;
i:integer;
begin
fpath:=path+'/*.*';
if FindFirst(fpath,faAnyFile,fs)=0 then
begin
if (fs.Name<>'.')and(fs.Name<>'..') then
if (fs.Attr and faDirectory)=faDirectory then
findall(path+'/'+fs.Name,fileresult)
else
fileresult.add(path+'/'+fs.Name);
while findnext(fs)=0 do
begin
if (fs.Name<>'.')and(fs.Name<>'..') then
if (fs.Attr and faDirectory)=faDirectory then
Findall(path+'/'+fs.Name,fileresult)
else begin
fileresult.add(path+'/'+fs.Name);
end;
end;
end;
Findclose(fs);
end;

本文介绍了一个使用Delphi编写的递归函数FindAll,该函数可以搜索指定路径及其子文件夹下的所有文件,并将结果保存到TStrings类型的变量中。通过调用FindFirst和FindNext函数遍历目录。

被折叠的 条评论
为什么被折叠?



