Einzelnen Beitrag anzeigen

Benutzerbild von Sir Rufo
Sir Rufo

Registriert seit: 5. Jan 2005
Ort: Stadthagen
9.454 Beiträge
 
Delphi 10 Seattle Enterprise
 
#33

AW: Datei öffnen / Dateiname Teil variabel

  Alt 23. Mai 2013, 19:34
Delphi-Quellcode:
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.
Kaum macht man's richtig - schon funktioniert's
Zertifikat: Sir Rufo (Fingerprint: ‎ea 0a 4c 14 0d b6 3a a4 c1 c5 b9 dc 90 9d f0 e9 de 13 da 60)
  Mit Zitat antworten Zitat