Einzelnen Beitrag anzeigen

kalmi01
(Gast)

n/a Beiträge
 
#6

Re: FindFirstFile: Wie suche ich auch in Unterordnern?

  Alt 3. Feb 2005, 07:54
Hi,
so kann man es machen, läuft mit ShellAPI:
Delphi-Quellcode:
  interface
    procedure DirSearch(SearchDir, SearchFile : string;
                        var DirList, FileList : TStringList);


  implementation
    procedure DirSearch(SearchDir, SearchFile : string;
                        var DirList, FileList : TStringList);
      var
        i : Integer;
        SearchRec : TSearchRec;
      begin
        if SearchDir[Length(SearchDir)] <> '\then SearchDir := SearchDir + '\';
        i := FindFirst(SearchDir + SearchFile, faDirectory, SearchRec);

        if DirectoryExists(SearchDir)
        then DirList.Add(Copy(SearchDir, 0, Length(SearchDir) -1));

        while i = 0
        do begin
             if (SearchRec.Name <> '.')
                and
                (SearchRec.Name <> '..')
             then begin
                    if DirectoryExists(SearchDir + SearchRec.Name)
                    then DirList.Add(SearchDir + SearchRec.Name);

                    if FileExists(SearchDir + SearchRec.Name)
                    then FileList.Add(SearchDir + SearchRec.Name);

                    SearchRec.Name := SearchDir + SearchRec.Name;
                    DirSearch(SearchRec.Name, SearchFile, DirList, FileList);
                  end;

             i := FindNext(SearchRec);
           end;
        FindClose(SearchRec);
      end;
Der Parameter fa.... gibt den Filetyp an, also z.B. alle Files (faAnyFile) oder nur Dir's (faDirectory).

Ich hoffe geholfen zu haben.
Gruß Michael
  Mit Zitat antworten Zitat