File library
Extensions of the File library, which reads and writes files anywhere in the game folder.
The library itself comes from the file binary module that the server opens on startup.
This file replaces File.write with a version that creates missing folders, and adds
recursive listing, wrappers around the built-in file functions that always work in the
game folder, and aliases such as File.rm, File.dir and File.is_folder.
Summary
Functions
Functions
Checks whether a file or folder exists.
Parameters
- filename String path relative to the game folder
Returns
- Boolean
Returns the extension of a file name.
Parameters
- filename String file name or path
Returns
- String extension without the dot, or nil if there is none
Finds the files and folders that match a wildcard.
Parameters
- filename String path with a wildcard relative to the game folder, e.g. 'gamemodes/*'
- sort String optional, defaults to
'nameasc'sorting order: 'nameasc', 'namedesc', 'dateasc' or 'datedesc'
Returns
- List<String> file names
- List<String> folder names
Lists all files inside of a folder and its subfolders. Subfolders whose name starts with a dot are skipped.
Parameters
- folder String folder path relative to the game folder
Returns
- List<String> file paths, each one starting with the folder path
Checks whether a path points to a folder.
Parameters
- filename String path relative to the game folder
Returns
- Boolean
Lists the names of the files and folders that match a wildcard as a single array.
Parameters
- path String path with a wildcard relative to the game folder, e.g. 'gamemodes/*'
- include_hidden Boolean optional, defaults to
falseinclude entries whose name starts with a dot
Returns
- List<String> file names followed by folder names, or nil if the search failed
Returns the file name part of a path.
Parameters
- filename String file path
Returns
- String file name including its extension
Returns the folder part of a path.
Parameters
- filename String file path
Returns
- String path up to and including the last slash
Returns the size of a file.
Parameters
- filename String file path relative to the game folder
Returns
- Number size in bytes, -1 if the file does not exist
Returns the time a file or folder was last modified at.
Parameters
- filename String path relative to the game folder
Returns
- Number UNIX timestamp, 0 if the file does not exist
Creates a file if it does not exist yet, by appending an empty string to it.
Parameters
- filename String file path relative to the game folder
Returns
- Any return value of File.append
Writes a string to a file, creating the missing folders of its path first. The path is relative to the game folder (garrysmod/).
Parameters
- file_name String file path, e.g. 'settings/flux/config.json'
- file_contents String contents to write