![]() |
|
|
#1
|
|||
|
|||
|
Как получить список файлов в папке, зная полный путь к ней?
|
|
#2
|
||||
|
||||
|
ниже path - путь к папке. вместо *.* любая маска. имена файлов добавляються в комбобокс1.
Код:
if FindFirst(path+'*.*', faAnyFile, fs)=0 then
repeat
ComboBox1.AddItem(fs.Name,nil);
until FindNext(fs)<>0;
FindClose(fs); |
|
#3
|
|||
|
|||
|
Спасибо большое!!!
![]() |
|
#4
|
||||
|
||||
|
А как получить не только список файлов в этой папке,но и ещё в подпапках???
|
|
#5
|
||||
|
||||
|
Знаешь что такое рекурсия?
Код:
procedure GetAllFiles( Path: string; Lb: TListBox );
var
sRec: TSearchRec;
isFound: boolean;
begin
isFound := FindFirst( Path + '\*.*', faAnyFile, sRec ) = 0;
while isFound do
begin
if ( sRec.Name <> '.' ) and ( sRec.Name <> '..' ) then
begin
if ( sRec.Attr and faDirectory ) = faDirectory then
GetAllFiles( Path + '\' + sRec.Name, Lb );
Lb.Items.Add( Path + '\' + sRec.Name );
end;
Application.ProcessMessages;
isFound := FindNext( sRec ) = 0;
end;
FindClose( sRec );
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
GetAllFiles( 'c:\windows', ListBox1 );
end; |