Files Delphi

Title: GetFileSizeFormat
Question: How to Display FileSize Like Windows Explorer
Answer:
function GetFileSizeFormat(Size: Int64): string;
const
Divisor: Array [0..3]of Double = (1024,1048576,1073741824,1099511627776);
var
i: Integer;
begin
Result := '';
if Size = 0 then
begin
Result := '0 Byte';
Exit;
end;
for i := High(divisor) downto low(divisor) do
begin
if (Size / divisor[i]) = 1 then
begin
Case i of
3 : Result := FormatFloat('#,##0.0',Size / divisor[i]) + ' TB';
2 : Result := FormatFloat('#,##0.0',Size / divisor[i]) + ' GB';
1 : Result := FormatFloat('#,##0.0',Size / divisor[i]) + ' MB';
0 : Result := FormatFloat('#,##0.0',Size / divisor[i]) + ' KB';
end;
Exit;
end;
end;
Result := FormatFloat('#,##0',Size) + ' Byte';
end;