function SizeToStr( Size : Int64 ) : string;
begin
if Size >= $10000000000 then
Result := Format('%.2f To', [Size / $10000000000])
else if Size >= $40000000 then
Result := Format('%.2f Go', [Size / $40000000])
else if Size >= $100000 then
Result := Format('%.2f Mo', [Size / $100000])
else if Size >= $400 then
Result := Format('%.2f Ko', [Size / $400] )
else
Result := Format('%d Octets', [Size] );
end;
// Recherche fichier
procedure ScanFile(Root,Extension: String; Item: TListItem; List: TListview; var ToSize: Int64);
var
Rec: TSearchRec;
begin
Root := IncludeTrailingPathDelimiter(Root);
Application.ProcessMessages;
if FindFirst(Root + Extension, faAnyFile - faDirectory, Rec) = 0 then
try
repeat
Item := List.Items.Add;
with Item do
begin
List.SmallImages := form1.ImageList1;
Caption := (Root);
SubItems.Add (Rec.Name);
inc(ToSize,Rec.Size);
SubItems.Add(SizeToStr(Rec.Size));
end;
until FindNext(Rec) <> 0;
SendMessage(List.Handle,WM_VSCROLL,SB_BOTTOM,0);
finally
FindClose(Rec);
end;
if FindFirst(Root + '*.*', faDirectory, Rec) = 0 then
try
repeat
if ((Rec.Attr and faDirectory) <> 0) and (Rec.Name <> '.') and
(Rec.Name <> '..') then
ScanFile(Root + Rec.Name, Extension, Item,List,ToSize);
until FindNext(Rec) <> 0;
finally
FindClose(Rec);
end;
form1.Label2.Caption := (SizeToStr(ToSize));
end;
procedure TForm1.Button1Click(Sender: TObject);
var
Item: TListItem;
I: Integer;
l : Int64;
begin
l := 0;
List1.Clear;
for I := 0 to List2.Items.Count -1 do
if List2.Items[I].Checked = true then
begin
ScanFile('C:\',List2.Items[I].Caption,Item,List1,l);
end;
end;