在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
procedure SearchFileEx(const ADir, AExt: string; AFiles: TStrings); var LSch: TSearchrec; LDir: string; begin if RightStr(Trim(ADir), 1) <> '\' then LDir := Trim(ADir) + '\' else LDir := Trim(ADir); if not DirectoryExists(LDir) then begin AFiles.Clear; Exit; end; if FindFirst(LDir + '*', faAnyfile, LSch) = 0 then begin repeat if ((LSch.Name = '.') or (LSch.Name = '..')) then Continue; if DirectoryExists(LDir + LSch.Name) then begin SearchFileEx(LDir + LSch.Name, AExt, AFiles); end else begin if (UpperCase(ExtractFileExt(LDir + LSch.Name)) = UpperCase(AExt)) or (AExt = '.*') then AFiles.Add(LDir + LSch.Name); end; until FindNext(LSch) <> 0; SysUtils.FindClose(LSch); end; end; 调用: procedure DecodeLog; var LPath: string; LFiles: TStringList; I: Integer; begin LPath := ExtractFilePath(Application.ExeName); LFiles := TStringList.Create; try SearchFileEx(LPath, '.Log', LFiles); for I := 0 to LFiles.Count - 1 do begin //Do something end; finally LFiles.Free; end; end; 主要运用到FindFirst,FindNext,FindClose来获取全部的子文件夹及文件 |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论