Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
function GetFileSize(sFileToExamine: string): string;
var SearchRec: TSearchRec;
sgPath: string;
inRetval, I1: Integer;
begin
sgPath :=ExpandFileName(sFileToExamine);
try
inRetval :=FindFirst(ExpandFileName(sFileToExamine), faAnyFile, SearchRec);
if inRetval=0 then I1 :=SearchRec.Size else I1 :=-1;
finally
SysUtils.FindClose(SearchRec);
end;
Result :=IntToStr(I1);
end;
Var
F : File;
FS : Cardinal;
begin
assignFile(F, ParamStr(1));
{$I-}
Reset (F, 1);
{$I+}
If (IOResult <> 0) Then
ShowMessage('Whoops! you really didn''t mean THAT file did you?')
Else
Begin
FS := FileSize(F);
If (FS = 0) Then
ShowMessage('So just how did you manage to create a 0 length file?')
Else
Begin
If ((FS div 1024) < 1024) Then // Bytes
ShowMessage('')
Else
If (FS Div (1024 * 1024) < 1024) Then // Kb
ShowMessage('')
Else
If (FS Div (1024 * 1024 * 1024) < 1024) Then // Mb
ShowMessage('')
// :
// etc
// :
// ad nauseum
End;
End;
function FileSizeStr ( filename: string ): string;
var
size: Int64;
handle: integer;
begin
handle := FileOpen(filename, fmOpenRead);
if handle = -1 then
result := 'Unable to open file ' + filename
else try
size := Int64(FileSeek(handle,Int64(0),2));
case Length(IntToStr(size)) of
1..3: result := Format ( '%d bytes', [size] );
4..6: result := Format ( '%f KB', [size / 1E3] );
7..9: result := Format ( '%f MB', [size / 1E6] );
10..12: result := Format ( '%f GB', [size / 1E9] );
13..15: result := Format ( '%f TB', [size / 1E12] );
end;
finally
FileClose ( handle );
end;
end;
function FileSizeStr ( filename: string ): string;
const
// K = Int64(1000); // Comment out this line OR
K = Int64(1024); // Comment out this line
M = K * K;
G = K * M;
T = K * G;
var
size: Int64;
handle: integer;
begin
handle := FileOpen(filename, fmOpenRead);
if handle = -1 then
result := 'Unable to open file ' + filename
else try
size := FileSeek ( handle, Int64(0), 2 );
if size < K then result := Format ( '%d bytes', [size] )
else if size < M then result := Format ( '%f KB', [size / K] )
else if size < G then result := Format ( '%f MB', [size / M] )
else if size < T then result := Format ( '%f GB', [size / G] )
else result := Format ( '%f TB', [size / T] );
finally
FileClose ( handle );
end;
end;