Szukanie na dysku

0

Jak moge przeszukac caly dysk w poszukiwaniu plikow? Slyszalem, ze trzeba to zrobic rekurencyjnie ale mi nie wyszlo...:-(

Help

0
Procedure FileSearch(const PathName, FileName : string; const InDir : boolean; Var StringList:TStringList);
Var Rec : TSearchRec;
    Path, CurFile, AllFiles : string;
    i: integer;
Begin
  Path := IncludeTrailingBackslash(PathName);
  AllFiles:=FileName;
  While AllFiles<>'' Do
  Begin
    I:=pos(';', AllFiles);
    If i=0 Then Begin
      CurFile:=Trim(AllFiles);
      AllFiles:='';
    End Else Begin
      CurFile:=Trim(Copy(AllFiles, 1, i-1));
      Delete(AllFiles, 1, i);
    End;
    If FindFirst(Path + CurFile, faAnyFile - faDirectory, Rec) = 0 Then
    Try
      Repeat
        StringList.Add(Path + Rec.name);
      Until FindNext(Rec) <> 0;
    Finally
      FindClose(Rec);
    End;
  End;
  If not InDir then Exit;
  If FindFirst(Path + '*.*', faDirectory, Rec) = 0 then
  Try
    Repeat
    If { (Rec.Attr and faDirectory) and } (Rec.name <> '.') and (Rec.name <> '..') then
    FileSearch(Path + Rec.name, FileName, True, StringList);
    Until FindNext(Rec) <> 0;
  Finally
    FindClose(Rec);
  End;
End;



procedure TMainFrm.Skanuj;
Var S:TStringList;
    I:Integer;
Begin
  S:=TStringList.Create;
  FileSearch(ExtractFilePath(EdtSciezka.Text),ExtractFileName(EdtSciezka.Text),True,S);
Listbox1.items.Add(S.Strings[i]);
    {tutaj wykonujesz swoje operacje w S.Strings[i] masz aktualna nazw pliku}
  End;
  S.Free;
end;

1 użytkowników online, w tym zalogowanych: 0, gości: 1