procedure FindFiles(FilesList: TStrings; Subdir: Boolean; StartDir, FileMask: string);
var
SR: TSearchRec;
DirList, DirlistOnly: TStringList;
IsFound: Boolean;
i, Count: integer;
begin
if StartDir[length(StartDir)] <> '\' then
StartDir := StartDir + '\';
IsFound := FindFirst(StartDir + FileMask, faAnyFile - faDirectory, SR) = 0;
while IsFound do
begin
begin
FilesList.Add(StartDir + SR.Name);
Count := Count + SR.Size;
end;
IsFound := FindNext(SR) = 0;
end;
FindClose(SR);
// Build a list of subdirectories
DirList := TStringList.Create;
IsFound := FindFirst(StartDir + '*.*', faAnyFile, SR) = 0;
while IsFound do
begin
if ((SR.Attr and faDirectory) <> 0) and (SR.Name <> '.') and (Subdir = true) and (SR.name <> '..') then
begin
DirList.Add(StartDir + SR.Name);
end;
IsFound := FindNext(SR) = 0;
end;
FindClose(SR);
// Scan the list of subdirectories
for i := 0 to DirList.Count - 1 do
begin
FindFiles(FilesList, Subdir, DirList, FileMask);
end;
DirList.Free;
end;
procedure TForm4.Button16Click(Sender: TObject);
begin
FindFiles(Memo1.Lines, false, 'X:\输出工具', '*.dcu');
end;