Get Exact File Size Using Delphi
| June 16, 2012 | Posted by Rivalina under Delphi, Object Pascal, Referensi, Sample Apps, Tips & Tricks, Win32 API |
Do not get messed with Windows API CreateFile(), OpenFile() and GetFileSize() to only get a file’s actual size. Using VCL component API wrapper TFileStream, we can do this faster:
We Need This Reusable Function
function ObtainFileSize(const AFile: String): Int64; begin with TFileStream.Create(AFile, fmOpenRead or fmShareDenyNone) do begin try Result := Size; finally Free; end; end; end;
We Use It Like This
procedure TForm1.Button1Click(Sender: TObject);
var
AFile: String;
iSize: Int64;
begin
AFile := Application.ExeName;
iSize := ObtainFileSize(AFile);
ShowMessage('Application EXE size: ' + IntToStr(iSize));d
end;
And Here’s Its Result
Incoming search terms:
- delphi file size
- delphi get file size
- delphi filesize
- delphi getfilesize
- opendialog in unigui
- getfilesize delphi
- delphi get filesize
- file size delphi
- get file size delphi
- unigui opendialog
Comments
Powered by Facebook Comments










This is the default footer layout. You can easily add or remove columns in the footer.