file.Read
From GMod Wiki
Function | |
Syntax |
file.Read( String filepath, [ Boolean usebasefolder ] ) Where is this used? |
Description: | |
Returns the contents of a file as a string. Returns nil if the file does not exist. | |
Returns: | String |
Part of Library: | File |
Realm: | |
BBCode Link: | [b][url=http://wiki.garrysmod.com/?title=File.Read]File.Read [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b] |
You may only Read files rooted from the gmod base folder. 'garrysmod/garrysmod/...' |
Examples
Description | This example prints the content of the my_mod/data.txt file to the console |
---|---|
Used on | |
Code | local contents = file.Read("my_mod/data.txt") Msg( contents ) |
Output | N/A |
Description | Reads one of the stock vmt files and prints it into your console |
---|---|
Used on | |
Code | print( file.Read("materials/vgui/sandbox.vmt", true) ) |
Output | The contents of sandbox.vmt in your console. |
Additional Notes
- Relative to garrysmod/data
- If usebasefolder is true then it starts relative to the GMod base folder (garrysmod/garrysmod).
- The returned string will appear to be missing line breaks if the file uses Mac format EOL characters. Notepad++'s EOL Conversion (located under Edit) can fix this.