Garry's Mod Wiki

file.Open

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

Description

Attempts to open a file with the given mode.

Arguments

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 gamePath
The path to look for the files and directories in. See this list for a list of valid paths.

Returns

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

Example

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()
Output:
// // Default mapcycle file for Garry's Mod. 45

Page Links


Special Pages


Wikis

?

Render Time: 75ms

DB GetPage 46
Generate Html 6
SaveChanges (1) 9
Render Body 0
Render Sidebar 12