- La fonction recursive pour ceux qui ont le fleme de D/L le zip :)
-
- procedure TMainPage.ScanFichiers( NomDossier : string ; subFolder : boolean );
- var
- DateOk : Boolean;
- TailleOk : Boolean;
- hFind : TSearchRec;
- begin
-
- NomDossier := slach(NomDossier);
-
- if FindFirst( NomDossier + '*.*', FaAnyFile, hFind ) = 0 then
- begin
-
- repeat
-
- if (hFind.Name <> '.') and (hFind.Name <> '..') then
- begin
-
- if ( hFind.Attr and faDirectory ) <> faDirectory then { c'est un fichier = traitment }
- begin
-
- { Compare Date fichier }
- case RadioDate.ItemIndex of
- 0: begin
- if DaysBetween( Now, FileDateToDateTime(hFind.Time) ) > StrToInt(TxtHighDate.Text) then DateOk := True Else DateOk := False;
- end;
- 1: begin
- if DaysBetween( Now, FileDateToDateTime(hFind.Time) ) < StrToInt(TxtLowDate.Text) then DateOk := True Else DateOk := False;
- end;
- 2: DateOK := True;
- end;
-
- { Compare Taille fichier }
- case RadioTaille.ItemIndex of
- 0: begin
- if Int( hFind.Size div 1000 ) > StrToInt(TxtHighSize.Text) then TailleOK := True Else TailleOK := False;
- end;
- 1: begin
- if Int( hFind.Size div 1000 ) < StrToInt(TxtLowSize.Text) then TailleOK := True Else TailleOK := False;
- end;
- 2: TailleOk := True;
- end;
-
- { Si condition reunis, efface le fichier }
- if DateOK and TailleOK then
- begin
-
- Grid.Cells[0, Grid.RowCount-1] := ( NomDossier + hFind.Name );
- Grid.Cells[1, Grid.RowCount-1] := IntToStr( (hFind.Size div 1000) );
- Grid.Cells[2, Grid.RowCount-1] := DateToStr( FileDateToDateTime( hFind.Time ) );
- if CheckSimu.Checked = True then
- Grid.Cells[3, Grid.RowCount-1] := 'Simulation'
- else begin
- if DeleteFile( NomDossier + hFind.Name ) then
- Grid.Cells[3, Grid.RowCount-1] := 'Effacer'
- else
- Grid.Cells[3, Grid.RowCount-1] := 'Erreur';
- end;
- Grid.RowCount := Grid.RowCount + 1;
-
- end;
- end else begin { c'est un dossier : on va voir dedans si subFolder = True }
-
- if subFolder = True then ScanFichiers( (slach(NomDossier) + hFind.Name), subFolder );
-
- end;
- end;
-
- until FindNext(hFind) <> 0;
-
- FindClose(hFind);
- Application.ProcessMessages
-
- end;
-
- end;
-
-
La fonction recursive pour ceux qui ont le fleme de D/L le zip :)
procedure TMainPage.ScanFichiers( NomDossier : string ; subFolder : boolean );
var
DateOk : Boolean;
TailleOk : Boolean;
hFind : TSearchRec;
begin
NomDossier := slach(NomDossier);
if FindFirst( NomDossier + '*.*', FaAnyFile, hFind ) = 0 then
begin
repeat
if (hFind.Name <> '.') and (hFind.Name <> '..') then
begin
if ( hFind.Attr and faDirectory ) <> faDirectory then { c'est un fichier = traitment }
begin
{ Compare Date fichier }
case RadioDate.ItemIndex of
0: begin
if DaysBetween( Now, FileDateToDateTime(hFind.Time) ) > StrToInt(TxtHighDate.Text) then DateOk := True Else DateOk := False;
end;
1: begin
if DaysBetween( Now, FileDateToDateTime(hFind.Time) ) < StrToInt(TxtLowDate.Text) then DateOk := True Else DateOk := False;
end;
2: DateOK := True;
end;
{ Compare Taille fichier }
case RadioTaille.ItemIndex of
0: begin
if Int( hFind.Size div 1000 ) > StrToInt(TxtHighSize.Text) then TailleOK := True Else TailleOK := False;
end;
1: begin
if Int( hFind.Size div 1000 ) < StrToInt(TxtLowSize.Text) then TailleOK := True Else TailleOK := False;
end;
2: TailleOk := True;
end;
{ Si condition reunis, efface le fichier }
if DateOK and TailleOK then
begin
Grid.Cells[0, Grid.RowCount-1] := ( NomDossier + hFind.Name );
Grid.Cells[1, Grid.RowCount-1] := IntToStr( (hFind.Size div 1000) );
Grid.Cells[2, Grid.RowCount-1] := DateToStr( FileDateToDateTime( hFind.Time ) );
if CheckSimu.Checked = True then
Grid.Cells[3, Grid.RowCount-1] := 'Simulation'
else begin
if DeleteFile( NomDossier + hFind.Name ) then
Grid.Cells[3, Grid.RowCount-1] := 'Effacer'
else
Grid.Cells[3, Grid.RowCount-1] := 'Erreur';
end;
Grid.RowCount := Grid.RowCount + 1;
end;
end else begin { c'est un dossier : on va voir dedans si subFolder = True }
if subFolder = True then ScanFichiers( (slach(NomDossier) + hFind.Name), subFolder );
end;
end;
until FindNext(hFind) <> 0;
FindClose(hFind);
Application.ProcessMessages
end;
end;