بدست اوردن حجم یک فایل

function Get_File_Size1(sFileToExamine: string; bInKBytes: Boolean): string;
var
FileHandle: THandle;
FileSize: LongWord;
d1: Double;
i1: Int64;
begin
//a- Get file size
FileHandle := CreateFile(PChar(sFileToExamine),
GENERIC_READ,
0, {exclusive}
nil, {security}
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL,
0);
FileSize := GetFileSize(FileHandle, nil);
Result := IntToStr(FileSize);
CloseHandle(FileHandle);
//a- optionally report back in Kbytes
if bInKbytes = True then
begin
if Length(Result) > 3 then
begin
Insert('.', Result, Length(Result) - 2);
d1 := StrToFloat(Result);
Result := IntToStr(round(d1)) + 'KB';
end
else
Result := '1KB';
end;
end;