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;