delphi 文件路径操作

System.IoUtils

https://www.cnblogs.com/cause/p/3500100.html

--------遍历文件----

procedure TForm1.Button4Click(Sender: TObject);
var
  path: string;
  sFile: string;
  fp: TDirectory.TFilterPredicate;
begin
fp := function(const Path: string; const SearchRec: TSearchRec): Boolean
begin
 Result :=(SearchRec.Attr and faHidden <> faHidden); //文件名包含'a'且不为隐藏文件
end;

path := 'X:\img';
for sFile in TDirectory.GetFiles(path, '*.*', TSearchOption.soAllDirectories,fp) do
ListBox1.Items.Add(sFile);

end;

 

---------

var
    sFile: string;
    fp: TDirectory.TFilterPredicate;
begin
    //
    fp := function(const Path: string; const SearchRec: TSearchRec): Boolean
        begin
            Result := (Pos('a', SearchRec.Name) > 0) and
              (SearchRec.Attr and faHidden <> faHidden); //文件名包含'a'且不为隐藏文件
        end;
    try
        for sFile in TDirectory.GetFiles(
                'H:\tmp1', //'H:\tmp1'
                '*.txt', //后缀为.txt
                TSearchOption.soAllDirectories,// 'H:\tmp1'目录下的所有文件
                fp) do
            ListBox1.Items.Add(sFile);
    except
        on e: Exception do
        begin
            MessageDlg(e.Message, mtError, [mbok], 0);
            Exit;
        end;
    end;
end;

 

 


 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值