Sets the current file position.
FileSetPos ( "filehandle", offset, origin )
| filehandle | The handle of a file, as returned by a previous call to FileOpen. |
| offset | The offset to move from the origin. This value may be positive or negative. Negative values move backwards from the origin. |
| origin | Must be one of the following: 0 - Beginning of the file ($FILE_BEGIN from Constants.au3). 1 - Current position ($FILE_CURRENT from Constants.au3). 2 - End of the file ($FILE_END from Constants.au3). |
| Success: | True if the operation succeeded. |
| Failure: | False. |
#include <Constants.au3>
Local Const $sFile = "test.txt"
Local $hFile = FileOpen($sFile, 2)
; Check if file opened for writing OK
If $hFile = -1 Then
MsgBox(0, "Error", "Unable to open file.")
Exit
EndIf
; Write something to the file.
FileWriteLine($hFile, "Line1")
FileWriteLine($hFile, "Line2")
FileWriteLine($hFile, "Line3")
; Flush the file to disk.
FileFlush($hFile)
; Check file position and try to read contents for current position.
MsgBox(0, "", "Position: " & FileGetPos($hFile) & @CRLF & "Data: " & @CRLF & FileRead($hFile))
; Now, adjust the position to the beginning.
Local $n = FileSetPos($hFile, 0, $FILE_BEGIN)
; Check file position and try to read contents for current position.
MsgBox(0, "", "Position: " & FileGetPos($hFile) & @CRLF & "Data: " & @CRLF & FileRead($hFile))
; Close the handle.
FileClose($hFile)
; Clean up the temporary file.
FileDelete($sFile)