- Documentation
- Shared functions
- fileOpen
Function
fileOpen
Opens an existing file for reading and writing (or read-only). On the server the path is relative to the resource folder and cannot leave it. On the client it first looks for the script's own files (written with fileCreate), then for <file> files sent by the server - those are read-only; ":other/file" points to another resource's file. Close the file with fileClose when done.
Syntax
file fileOpen(string filePath [, bool readOnly = false])Arguments
filePathstring- File path.
readOnlybool, optional = falsetrue= read only.
Returns
A file handle, or false when the file does not exist.
Example
local file = fileOpen("log.txt")
if file then
fileSetPos(file, fileGetSize(file))
fileWrite(file, os.date("[%H:%M] ") .. "Start zasobu\n")
fileClose(file)
end
See also
fileCreateCreates a new file or empties an existing one and opens it for writing. On the client the files go to a private folder for that server on the player's computer (limit 64 MB per file and 256 MB per server).fileReadReads the given number of bytes from the current position and moves the position. At the end of the file it returns an empty string. Binary data is returned unchanged.fileWriteWrites strings from the current position (each argument one after another) and moves the position. Supports binary data.fileCloseCloses a file and writes its buffer to disk. The handle becomes invalid.fileGetContentsReads a whole file in one call. Accepts a file handle or a path (it then opens and closes the file itself).