1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62:
| unit Dsuche;
interface uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls;
procedure GetFiles(const Directory: string; var Files:TStrings; const FileMask: string = '*.*'; const SubFolders: Boolean = False);
implementation uses Unit1,Tabelle,Unit6;
procedure GetFiles(const Directory: string; var Files: TStrings; const FileMask: string = '*.*'; const SubFolders: Boolean = False);
//Hilfsfunktion, um Schrägstriche hinzuzfügen, wenn nötig function SlashSep(const Path, S: string): string; begin if AnsiLastChar(Path)^ <> '\' then Result := Path + '\' + S else Result := Path + S; end;
var SearchRec: TSearchRec; begin //Zuerst alle Dateien im aktuelle Verzeichnis finden
if FindFirst(SlashSep(Directory, FileMask), faAnyFile-faDirectory-faVolumeID, SearchRec) = 0 then begin try repeat Files.Add(SlashSep(Directory, SearchRec.Name)); until FindNext(SearchRec) <> 0; finally SysUtils.FindClose(SearchRec); end; end;
//Als nächstes nach Unterverzeichnissen suchen und, wenn benötigt, durchsuchen if SubFolders then begin if FindFirst(SlashSep(Directory,'*.*'), faAnyFile, SearchRec) = 0 then begin try repeat //Wenn es ein Verzeichnis ist, Rekursion verwenden if (SearchRec.Attr and faDirectory) <> 0 then begin if ((SearchRec.Name <> '.') and (SearchRec.Name <> '..')) then GetFiles(SlashSep(Directory, SearchRec.Name), Files, FileMask, SubFolders); end; until FindNext(SearchRec) <> 0; finally SysUtils.FindClose(SearchRec); end; end; end;
end; end. |