最近用C#做一个根据自定义条件Search file 的工具, 查找相关方面的资料:

function GetFilenames(FilePath,ExtMask: String):TStrings;   //遍历目录
var
  FileRec :TSearchrec;
begin
  if DirectoryExists(FilePath) then
  begin
    if FilePath[Length(FilePath)] <> '\' then FilePath := FilePath + '\';
    Result := TStringList.Create;
    if FindFirst(FilePath + ExtMask,faAnyfile,FileRec) = 0 then
    repeat
      if (FileRec.Attr and faDirectory) = 0 then
          Result.Add(FilePath + FileRec.Name);
    until FindNext(FileRec) <> 0;
    FindClose(FileRec);
  end;
end;


function GetFilenamesEx(FilePath,ExtMask :String):TStrings;   //遍历目录及子目录
var
  FileRec :TSearchrec;
begin
  if DirectoryExists(FilePath) then
  begin
    if FilePath[Length(FilePath)] <> '\' then FilePath := FilePath + '\';
    Result := TStringList.Create;
    if FindFirst(FilePath + ExtMask,faAnyfile,FileRec) = 0 then
    repeat
      if (FileRec.Attr and faDirectory) <> 0 then
      begin
        if (FileRec.Name<> '.') and (FileRec.Name  <> '..') then
          Result.AddStrings(GetFilenames(FilePath + FileRec.Name + '\',ExtMask));
        end
      else Result.Add(FilePath + FileRec.Name);
    until FindNext(FileRec) <> 0;
    FindClose(FileRec);
  end;
end;

相关文章:

  • 2021-05-16
  • 2021-05-29
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-12-13
  • 2021-12-08
  • 2021-11-18
  • 2022-12-23
  • 2021-06-09
相关资源
相似解决方案