Name
FileSize Function
Syntax
function FileSize(var F: File): LongInt; function FileSize(var F: TextFile): LongInt;
Description
FileSize returns the size in records of the file
F. If F is a
TextFile, the record size is arbitrarily chosen as
the buffer size, which defaults to 128. If F is an untyped binary
file, the record size is determined when the file is opened.
FileSize is not a real
function.
Errors
If the file
Fis not open,FileSizereports I/O error 103.Real text files don’t have fixed-size records, so
FileSizeis useless for text files. Use streams or call the Windows API functionGetFileSizeinstead of callingFileSize.
// Return the size in bytes of a text file or -1 for an error.
function TextFileSize(var F: TextFile): LongInt;
begin
case TTextRec(F).Mode of
fmInput, fmOutput: Result := GetFileSize(TTextRec(F).Handle, nil);
else Result := -1;
end;
end;FileSizedoes not support files larger than 2 GB. See theFileSeekfunction in theSysUtilsunit, or call the Windows API for large files.
See Also
| Eof Function, File Keyword, FilePos Function, IOResult Function, Reset Procedure, Rewrite Procedure, Seek Procedure, TextFile Type, Truncate Procedure |
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access