Garry's Mod Wiki


File file.Open( string fileName, string fileMode, string path )


Attempts to open a file with the given mode.


1 string fileName
The files name. See file.Write for details on filename restrictions when writing to files.
2 string fileMode
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
3 string path
The path type. See File Search Paths

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.


1 File
The opened file object, or nil if it failed to open due to it not existing or being used by another process.


Open a file in read only mode, reads a line, tells where the current file pointer is at and then closes the file handle.

local f = file.Open( "cfg/mapcycle.txt", "r", "MOD" ) print( f:ReadLine() ) print( f:ReadLine() ) print( f:Tell() ) f:Close()
// // Default mapcycle file for Garry's Mod. 45

Page Links

Special Pages



Render Time: 41ms

DB GetPage 3
Generate Html 15
SaveChanges (1) 8
Render Body 0
Render Sidebar 12