delphi FindFiles获取目录下所有文件


本文整理自网络,侵删。

 
procedure FindFiles(FilesList: TStrings;Subdir : Boolean; StartDir, FileMask: string);
var
  SR: TSearchRec;
  DirList,DirlistOnly: TStringList;
  IsFound: Boolean;
  i,Count: integer;
begin
  If StartDir[length(StartDir)] <> '\' then
    StartDir := StartDir + '\';
  IsFound :=
    FindFirst(StartDir+FileMask, faAnyFile-faDirectory, SR) = 0;
  while IsFound do begin
   Begin
    FilesList.Add(StartDir + SR.Name);
    Count:= Count + Sr.Size;
   end;
    IsFound := FindNext(SR) = 0;
  end;
  FindClose(SR);

  // Build a list of subdirectories
  DirList := TStringList.Create;
  IsFound := FindFirst(StartDir+'*.*',
                        faAnyFile
                        , SR) = 0;
  while IsFound do begin
    if ((SR.Attr and faDirectory)<> 0) and
         (SR.Name <> '.') and   (subdir = true) and (sr.name <> '..') then
    Begin
      DirList.Add(StartDir + SR.Name);
    end;
    IsFound := FindNext(SR) = 0;
  end;
  FindClose(SR);

  // Scan the list of subdirectories www.delphitop.com
  for I := 0 to DirList.Count - 1 do
  Begin
    FindFiles(FilesList, SubDir,DirList[i], FileMask);
  end;
  DirList.Free;
end;

调用:FindFiles(Memo1.Lines,false,'c:\','*.*');

相关阅读 >>

Delphi 多关键词批量替换

Delphi inputbox 输入时显示*号

Delphi d10.x 安卓app开发中创建密钥库文件

Delphi 判断素数的简单例子

Delphi tstringbuilder详解

Delphi写入txt

Delphi用idhttp提交自定义cookie

xe7提示找不到sharedactivitycontext函数

Delphi dbnavigator1 删除时弹出确认对话框

Delphi 读取流 image1 stream 加载到image2 timage 对象

更多相关阅读请进入《Delphi》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...