program DateienSuchen;
{$APPTYPE CONSOLE}
{$R *.res}
uses
System.SysUtils;
type
TDynStringArray =
array of string;
function GetFileArray(
const ASearchStr :
string ) : TDynStringArray;
var
LFileCount : Integer;
LPath :
string;
LSearchRec : TSearchRec;
begin
LFileCount := 0;
SetLength( Result, 10 );
LPath := ExtractFilePath( ASearchStr );
if FindFirst( ASearchStr, faAnyFile, LSearchRec ) = 0
then
try
repeat
if LSearchRec.Attr
and faDirectory = faDirectory
then
Continue;
if LFileCount > High( Result )
then
SetLength( Result, LFileCount + 10 );
Result[LFileCount] := LPath + LSearchRec.
Name;
Inc( LFileCount );
until FindNext( LSearchRec ) <> 0;
SetLength( Result, LFileCount );
finally
FindClose( LSearchRec );
end;
end;
procedure Test;
var
LFiles : TDynStringArray;
LIdx : Integer;
begin
LFiles := GetFileArray( '
C:\*.*' );
for LIdx := Low( LFiles )
to High( LFiles )
do
WriteLn( LFiles[LIdx] );
end;
begin
try
Test;
except
on E :
Exception do
WriteLn( E.ClassName, '
: ', E.
Message );
end;
ReadLn;
end.