Seek
Jump to navigation
Jump to search
Moves the current position of a file to a specified component.
- Declaration
procedure Seek(var F; N: Longint);
- Target
- Windows, Real, Protected
- Remarks
- F is any file variable type except text, and N is an expression of type Longint. The current file position of F is moved to component number N. The number of the first component of a file is 0. To expand a file, you can seek one component beyond the last component; that is, the statement Seek(F, FileSize(F)) moves the current file position to the end of the file.
- With {$I-}, IOResult returns 0 if the operation was successful. Otherwise, it returns a nonzero error code.
- Restrictions
- Cannot be used on text files.
- 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.