The function gets the size of the file. The file size can be over 2 GB.
1 2 3 4 5 6 7 8 9 |
var path: string; size: int64; begin path:= 'C:\Windows\notepad.exe'; size:= fileGetSize(path); ShowMessage(IntToStr(size) + ' byte'); end; |
Options
path - file path
Result
File size in bytes.
If the file does not exist: -1.
1 2 3 4 5 6 7 8 9 10 11 |
function fileGetSize(var fileName: string): Int64; var sr : TSearchRec; begin if FindFirst(fileName, faAnyFile, sr ) = 0 then result := Int64(sr.FindData.nFileSizeHigh) shl Int64(32) + Int64(sr.FindData.nFileSizeLow) else result := -1; FindClose(sr); end; |