delphi XE 枚举指定目录及子目录下的所有文件  
官方Delphi 学习QQ群: 682628230(三千人)
频道

delphi XE 枚举指定目录及子目录下的所有文件


procedure DoEnumAllFiles(strPath: string;FileList: TStrings);{功能:枚举指定目录及子目录下的所有文件}
var
  sr: TSearchRec;

begin
  if strPath = '' then Exit;

  strPath := IncludeTrailingPathDelimiter(strPath);

  if not DirectoryExists(strPath) then Exit;

  if FindFirst(strPath + '*.*', System.SysUtils.faAnyFile, sr) = 0 then
  begin
    try
      repeat
        //非目录的,就是文件
        if (sr.Attr and System.SysUtils.faDirectory = 0 ) then
        begin
          FileList.Add(strPath + sr.Name);
        end;
      until FindNext(sr) <> 0;
    finally
      System.SysUtils.FindClose(sr);
    end;
  end;

  //查找子目录。
  if FindFirst(strPath + '*', System.SysUtils.faDirectory, sr) = 0 then
  begin
    try
      repeat
        if (sr.Attr and System.SysUtils.faDirectory<>0) and (sr.Name<>'.') and (sr.Name<>'..') then
        begin
          DoEnumAllFiles(strPath + sr.Name, FileList);
        end;
      until FindNext(sr) <> 0;
    finally
      FindClose(sr);
    end;
  end;

end;


推荐分享
图文皆来源于网络,内容仅做公益性分享,版权归原作者所有,如有侵权请告知删除!
 

Copyright © 2014 DelphiW.com 开发 源码 文档 技巧 All Rights Reserved
晋ICP备14006235号-8 晋公网安备 14108102000087号

执行时间: 0.046677112579346 seconds