procedure FindFiles(FilesList: TStringList; StartDir, FileMask: string);
var
SR: TSearchRec;
DirList: TStringList;
IsFound: Boolean;
i: integer;
begin
if StartDir[length(StartDir)] <> '\' then
StartDir := StartDir + '\';
IsFound := FindFirst(StartDir + FileMask, faAnyFile - faDirectory, SR) = 0;
while IsFound do
begin
FilesList.Add(StartDir + SR.Name);
IsFound := FindNext(SR) = 0;
end;
FindClose(SR);
DirList := TStringList.Create;
IsFound := FindFirst(StartDir + '*.*', faAnyFile, SR) = 0;
while IsFound do
begin
if ((SR.Attr and faDirectory) <> 0) and (SR.Name[1] <> '.') then
DirList.Add(StartDir + SR.Name);
IsFound := FindNext(SR) = 0;
end;
FindClose(SR);
for i := 0 to DirList.Count - 1 do
FindFiles(FilesList, DirList[i], FileMask);
DirList.Free;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
FilesList: TStringList;
i: integer;
begin
FilesList := TStringList.Create;
try
FindFiles(FilesList, EditStartDir.Text, '*.mp3'); <---- здесь можно ставить что ищем.
ListBox1.Items.Assign(FilesList)
Label1.Caption := 'Найдено файлов: ' + IntToStr(FilesList.Count);
Label1.Visible := True;
if FilesList.Count = 0 then
ShowMessage('Ничего не найдено');
finally
FilesList.Free;
end;
end;
procedure TForm1.ListBox1DblClick(Sender: TObject);
Var
s: String;
begin
s := Form1.ListBox1.Items.Strings[ListBox1.ItemIndex];
ShellExecute(0, 'open', PChar(s), nil, nil, SW_SHOW);
end;