Garry's Mod Wiki

Revision Difference

file.Open#528498

<function name="Open" parent="file" type="libraryfunc"> <description>Attempts to open a file with the given mode.</description> <realm>Shared and Menu</realm> <args> <arg name="fileName" type="string">The files name. See <page>file.Write</page> for details on filename restrictions when writing to files.</arg> <arg name="fileMode" type="string">The mode to open the file in. Possible values are: * **r** - read mode * **w** - write mode * **a** - append mode * **rb** - binary read mode * **wb** - binary write mode * **ab** - binary append mode</arg> <arg name="path" type="string">The path type. See <page>File Search Paths</page> Common paths are: * "GAME" - Structured like base folder (garrysmod/), searches all the mounted content (main folder, addons, mounted games etc) * "LUA" or "lsv" - All Lua folders (lua/) including gamesmodes and addons * "DATA" - Local to Data folder, has write access (garrysmod/data) * "MOD" - Strictly the game folder (garrysmod/), ignores mounting.</arg> </args> <rets> <ret name="" type="File">The opened file object, or nil if it failed to open due to it not existing or being used by another process.</ret> </rets> </function> <example> <description>Open a file in read only mode, reads a line, tells where the current file pointer is at and then closes the file handle.</description> <code> local f = file.Open( "cfg/mapcycle.txt", "r", "MOD" ) print( f:ReadLine() ) print( f:ReadLine() ) print( f:Tell() ) f:Close() </code> <outputfixedwidth>Fixed width</outputfixedwidth>⤶ <output> ``` // // Default mapcycle file for Garry's Mod. 45 ``` </output> </example>