Einzelnen Beitrag anzeigen

omata

Registriert seit: 26. Aug 2004
Ort: Nebel auf Amrum
3.154 Beiträge
 
Delphi 7 Enterprise
 
#3

AW: Brauche Hilfe bei Rekursion

  Alt 3. Jan 2012, 22:54
Delphi-Quellcode:
uses SysUtils;

procedure getFilesInDirectory(Directory: string; const Mask: string;
                              WithSubDirs: Boolean; Files:TStrings);

  procedure ScanDir(const Directory: string);
  var SR: TSearchRec;
  begin
    if FindFirst(Directory + Mask, faAnyFile and not faDirectory, SR) = 0 then
    begin
      try
        repeat
          Files.Append(Directory + SR.Name);
        until FindNext(SR) <> 0;
      finally
        FindClose(SR);
      end;
    end;

    if WithSubDirs then begin
      if FindFirst(Directory + '*.*', faAnyFile, SR) = 0 then
      begin
        try
          repeat
            if ((SR.attr and faDirectory) = faDirectory)
               and (SR.Name <> '.')
               and (SR.Name <> '..') then
            begin
              ScanDir(Directory + SR.Name + '\');
            end;
          until FindNext(SR) <> 0;
        finally
          FindClose(SR);
        end;
      end;
    end;
  end;

begin
  if trim(Directory) <> 'then begin
    if Directory[Length(Directory)] <> '\then
      Directory := Directory + '\';
    Files.Clear;
    ScanDir(Directory);
  end;
end;
  Mit Zitat antworten Zitat