FileSize
Jump to navigation
Jump to search
Returns the current size of a file.
- Declaration
function FileSize(var F): Longint;
- Target
- Windows, Real, Protected
- Remarks
- F is a file variable. FileSize(F) returns the number of components in F. If the file is empty, FileSize(F) returns 0.
- With {$I-}, IOResult returns 0 if the operation was successful; otherwise, it returns a nonzero error code.
- Restrictions
- Cannot be used on a text file. File must be open.
- See Also
- FilePos
Sample Code
{FilePos.PAS} {Sample code for the FilePos and FileSize functions, and the Seek procedure.} { For Windows: } { uses WinCrt; } var f: file of Byte; size : Longint; begin { Get file name from command line } Assign(f, ParamStr(1)); Reset(f); size := FileSize(f); Writeln('File size in bytes: ',size); Writeln('Seeking halfway into file...'); Seek(f,size div 2); Writeln('Position is now ',FilePos(f)); Close(f); end.