Search for files in Delphi
提示:文件夹中快速搜索
核心源码
// Procedure to find files
procedure TForm1.FindIt(fPath, fFile: UnicodeString; SubDir: boolean);
var
Rec: TSearchRec;
Path: UnicodeString;
begin
Path := IncludeTrailingPathDelimiter(fPath);
if FindFirst(Path + fFile, faAnyFile - faDirectory, Rec) = 0 then
try
repeat
ListBox1.Items.Add(Path + Rec.Name);
until FindNext(Rec) <> 0;
finally
FindClose(Rec);
end;
// If include subfolders is true
if SubDir then
if FindFirst(Path + ‘.’, faDirectory, Rec) = 0 then
try
repeat
if ((Rec.Attr and faDirectory) <> 0) and (Rec.Name <> ‘.’) and
(Re