文件夹查找文件(一个文件夹文件查找函数 Delphi)

procedure TfrmMain.SearchPath(path, filename: string; recurse: Boolean;
  List: TStringList);   //recurse  是否包递归查找目录
  procedure Traverse(APath: string);
  var
    f: TSearchRec;
    I: Integer;
  begin
    if recurse then
    begin
      if FindFirst(APath + filename,faDirectory,f) = 0 then
      repeat
        if (f.Name[1] <> '.') then
          Traverse(IncludeTrailingPathDelimiter(APath + f.Name));
      until FindNext(f) <> 0;
      FindClose(f);
    end;

    if FindFirst(APath + filename,faReadOnly or faHidden or faSysFile or faArchive, f) = 0 then
    repeat
      List.Add(APath + f.Name);
    until FindNext(f) <> 0;
    FindClose(f);
  end;
begin
  Traverse(IncludeTrailingPathDelimiter(path));
end;
posted @ 2015-03-22 16:20  hongjack  阅读(3195)  评论(0编辑  收藏  举报