【发布时间】:2017-01-06 03:15:51
【问题描述】:
我正在使用此线程 (How to Search a File through all the SubDirectories in Delphi) 中的代码递归查找文件:
procedure FindFilePattern(root:String;pattern:String);
var
SR:TSearchRec;
begin
root:=IncludeTrailingPathDelimiter(root);
if FindFirst(root+'*.*',faAnyFile,SR) = 0 then
begin
repeat
Application.ProcessMessages;
if ((SR.Attr and faDirectory) = SR.Attr ) and (pos('.',SR.Name)=0) then
FindFilePattern(root+SR.Name,pattern)
else
begin
if pos(pattern,SR.Name)>0 then Form1.ListBox1.Items.Add(Root+SR.Name);
end;
until FindNext(SR)<>0;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
FindFilePattern('C:\','.exe');
end;
它正在工作,但由于某种原因它忽略了目录 Program Files、Program Files (x86) 和 Users。不幸的是,我正在搜索的文件在这些文件夹中。有人知道为什么会这样吗?
任何提示都会非常有帮助,
谢谢
【问题讨论】:
-
你说的似乎不太合理。您的代码不会跳过程序文件文件夹。