DELPHI XE2 遍历子目录及文件《转》

function MakeFileList(Path,FileExt:string):TStringList ;
var
  sch:TSearchrec;
begin
  Result:=TStringlist.Create;

  if rightStr(trim(Path), 1) <> '\' then
    Path := trim(Path) + '\'
  else
    Path := trim(Path);

  if not DirectoryExists(Path) then
  begin
    Result.Clear;
    exit;
  end;

  if FindFirst(Path + '*', faAnyfile, sch) = 0 then
  begin
    repeat
       Application.ProcessMessages;
       if ((sch.Name = '.') or (sch.Name = '..')) then Continue;
       if DirectoryExists(Path+sch.Name) then
       begin
         Result.AddStrings(MakeFileList(Path+sch.Name,FileExt));
       end
       else
       begin
         if (UpperCase(extractfileext(Path+sch.Name)) = UpperCase(FileExt)) or (FileExt='.*') then
         Result.Add(Path+sch.Name);
       end;
    until FindNext(sch) <> 0;
    FindClose(sch);
  end;
end;
procedure TForm1.FormCreate(Sender: TObject);
var
  I : integer;
begin
  lst1.Items := MakeFileList(ExtractFilePath(Application.ExeName)+'Report','.fr3');
  for I := 0 to lst1.Count -1 do
    begin
      lst1.Items[I] := StringReplace(StringReplace(lst1.Items[I],ExtractFilePath(Application.ExeName)+'Report','',[rfReplaceAll, rfIgnoreCase]),'\','',[rfReplaceAll, rfIgnoreCase]);
    end;
  if lst1.Items[0] = '' then
    lst1.Items.Delete(0);

    cbb1.Clear;
  for I := 0 to lst1.Count -1 do
    begin
      cbb1.Items.Add(lst1.Items[I]);
      cbb1.ItemIndex := 0;
    end;
  lst1.Clear;
end;

 

转载于:https://www.cnblogs.com/LceMeaning/p/4195970.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值