var Form1: TForm1; ResultFichier : Integer; ResultDossier : Integer; StopProcess : Boolean; MonTableau : array of array of String; function ListFiles(Chemin, FindF:String; List:TStrings):Integer; Var S : TSearchRec; begin Chemin:=IncludeTrailingPathDelimiter(Chemin); Result:=0; If FindFirst(Chemin+'*.*',faAnyFile,S)=0 then begin repeat Application.ProcessMessages; if (StopProcess) then Exit else begin if (S.Name<>'.')And(s.Name<>'..')then begin if (S.Attr And faDirectory)<>0 then begin ListFiles(Chemin+S.FindData.cFileName,FindF,List); Inc(ResultDossier); end else begin if MatchesMask(S.Name, FindF) then begin Inc(ResultFichier); List.Add(S.Name+' (Index '+IntTostr(ResultFichier-1)+')'); SetLength(MonTableau[0],ResultFichier); SetLength(MonTableau[1],ResultFichier); MonTableau[0,ResultFichier-1]:='Index '+IntTostr(ResultFichier-1); MonTableau[1,ResultFichier-1]:=Chemin+S.Name; end; end; end; end; Until FindNext(S) <> 0; FindClose(S); end; end; procedure TForm1.BitBtn1Click(Sender: TObject); begin ResultFichier:=0; ResultDossier:=0; CheckListBox1.Clear; SetLength(MonTableau,2); Label1.Caption:='Recherche dans C:\Test'; ListFiles('C:\Test','TTTT*.*',CheckListBox1.Items); Label2.Caption:=Format('Resultats : %d Dossiers et %d Fichiers',[ResultDossier,ResultFichier]); end;
var Form1: TForm1; StopProcess : Boolean; function ListFiles(Chemin, FindF:String; List:TStrings):Integer; var S : TSearchRec; begin Chemin:=IncludeTrailingPathDelimiter(Chemin); Result:=0; If FindFirst(Chemin+'*.*',faAnyFile,S)=0 then repeat Application.ProcessMessages; if (StopProcess) then Exit else if (S.Name<>'.')And(s.Name<>'..')then if (S.Attr And faDirectory)<>0 then ListFiles(Chemin+S.FindData.cFileName,FindF,List) else if MatchesMask(S.Name, FindF) then List.Add(Chemin+S.Name); Until FindNext(S) <> 0; FindClose(S); end; procedure TForm1.BitBtn1Click(Sender: TObject); begin CheckListBox1.Style:=lbOwnerDrawFixed; CheckListBox1.Clear; Label1.Caption:='Recherche dans '+Direct; ListFiles('C:\Test','TTTT*.*',CheckListBox1.Items); end; procedure TForm1.CheckListBox1DrawItem(Control: TWinControl; Index: Integer; Rect: TRect; State: TOwnerDrawState); begin with CheckListBox1 do Canvas.TextRect(Rect,Rect.Left, Rect.Top,ExtractFileName(Items[Index])); end;
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre questionvar Form1: TForm1; c: Integer; b: Integer; //Result : Integer; ResultTotal : Integer; StopProcess : Boolean; MonTableau: array of array of String; function ListFiles(Chemin:String):Integer; var S : TSearchRec; begin Chemin:=IncludeTrailingPathDelimiter(Chemin); Form1.Label1.Caption:='Recherche dans '+Chemin; Form1.CheckListBox1.Refresh; Result:=0; SetLength(MonTableau,2); If FindFirst(Chemin+'*.*',faAnyFile,S)=0 then begin repeat Application.ProcessMessages; if (StopProcess) then exit else if (S.Name<>'.')And(s.Name<>'..') then begin if (S.Attr And faDirectory)<>0 then begin Result:=Result+ListFiles(Chemin+S.FindData.cFileName); Inc(ResultTotal); end else if MatchesMask(S.Name, 'TTTT*.*') then begin Form1.CheckListBox1.Items.Add(S.Name); Inc(Result); SetLength(MonTableau[0],Result); SetLength(MonTableau[1],Result); For b:=0 To Form1.CheckListBox1.Items.Count-1 do // c'est ici que ça pose problème begin MonTableau[0,b]:=IntToStr(b+1); MonTableau[1,b]:=Form1.CheckListBox1.Items[b]; // c'est ici que ça pose problème end; end; end; Until FindNext(S) <> 0; FindClose(S); end; end;
Form1.CheckListBox1.Items.Add(S.Name); Inc(Result); SetLength(MonTableau[1],Result-1); MonTableau[0,Result -1]:=IntToStr(Result-1); MonTableau[1,Result -1]:=Chemin+S.Name;