From Multi Theft Auto: Wiki
Revision as of 18:08, 28 December 2014 by Qaisjp (talk | contribs) (add oop syntax)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Returns the current read/write position in the given file.


 int fileGetPos ( file theFile ) 

OOP Syntax Help! I don't understand this!

Method: file:getPos(...)
Variable: .pos
Counterpart: fileSetPos

Required Arguments

  • theFile: the file handle you wish to get the position of.


Returns the file position if successful, or false if an error occured (e.g. an invalid handle was passed).


This example opens the file test.txt and outputs its contents and current read position to the console.

local hFile = fileOpen("test.txt", true)       -- attempt to open the file (read only)
if hFile then                                  -- check if it was successfully opened
    local buffer
    while not fileIsEOF(hFile) do              -- as long as we're not at the end of the file...
        buffer = fileRead(hFile, 500)          -- ... read the next 500 bytes...
        outputConsole(buffer.."Current Position: "..fileGetPos(hFile))                  -- ... and output them to the console and outputs the current read position
    fileClose(hFile)                           -- close the file once we're done with it
    outputConsole("Unable to open test.txt")

See Also