刚引用过:
//在资料里找找吧,这个应该是最经典的了:
//遍历指定目录下的所有文件
procedure FindFiles(APath, AFile: string;Strings1:Tstrings);
var
FindResult: integer;
FSearchRec, DSearchRec: TSearchRec;
function IsDirNotation(ADirName: string): Boolean;
begin
Result := ((ADirName = '.') or (ADirName = '..'));
end;
begin
if APath[Length(APath)] <> '/' then
APath := APath + '/';
FindResult := FindFirst(APath + AFile, faAnyFile + faHidden +faSysFile + faReadOnly, FSearchRec); //在根目录中查找指定文件
try
while FindResult = 0 do
begin
Strings1.Add(APath + FSearchRec.Name);
FindResult := FindNext(FSearchRec); // 查找下一个指定文件
end;
FindResult := FindFirst(APath + '*.*', faDirectory, DSearchRec); //进入当前目录的子目录继续查找
while FindResult = 0 do
begin
if ((DSearchRec.Attr and faDirectory) = faDirectory) and not IsDirNotation(DSearchRec.Name) then
FindFiles(APath + DSearchRec.Name, AFile,Strings1); //递归调用FindFiles函数
FindResult := FindNext(DSearchRec);
end;
finally
FindClose(FSearchRec);
end;
end;