Garry's Mod Wiki


You might be looking for the File class, which has the same name as this library.

The file library provides functions for finding, reading and writing to files.
The following path values are most commonly used:

  • LUA searches the lua files (in /lua/, in your gamemodes, in all the addons).
  • GAME searches all the mounted content (main folder, addons, mounted games etc).
  • MOD searches only the garrysmod folder.
  • DATA searches in the data folder.

See File Search Paths for the descriptive list of path values. For the full list of path values, type path in the console.


file.Append( string name, string content )
Appends a file relative to the data folder.
file.CreateDir( string name )
Creates a directory that is relative to the data folder.
file.Delete( string name )
Deletes a file or empty folder that is relative to the data folder. You can't remove any files outside of data folder.
boolean file.Exists( string name, string path )
Returns a boolean of whether the file or directory exists or not.
table, table file.Find( string name, string path, string sorting = "nameasc" )
Returns a list of files and directories inside a single folder.
boolean file.IsDir( string fileName, string path )
Returns whether the given file is a directory or not.
File file.Open( string fileName, string fileMode, string path )
Attempts to open a file with the given mode.
string file.Read( string fileName, string path = "DATA" )
Returns the content of a file. Beware of casing -- some filesystems are case-sensitive. SRCDS on Linux seems to force file/directory creation to lowercase, but will not modify read operations.
boolean file.Rename( string orignalFileName, string targetFileName )
Attempts to rename a file with the given name to another given name. This function is constrained to the data/ folder.
file.Size( string fileName, string path )
Returns the file's size in bytes. If the file is not found, returns -1.
number file.Time( string path, string gamePath )
Returns when the file or folder was lasted modified in Unix time.
file.Write( string fileName, string content )
Writes the given string to a file. Erases all previous data in the file. To add data without deleting previous data, use file.Append.

Page Links

Special Pages



Render Time: 43ms

DB GetPage 3
Generate Html 6
SaveChanges (1) 19
Render Body 0
Render Sidebar 12