file.Read
From GMod Wiki
| Function | |
| Syntax |
file.Read( Where is this used? |
| Description: | |
| Returns the contents of a file as a string. Returns nil if the file does not exist. | |
| Returns: |
|
| Part of Library: |
|
| Available On: |
|
| 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/...' |
| You can only Read text data. Binary data is not mutable inside Garry's Mod using the File library. |
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 | None. |
| Description | Reads one of the stock vmt files and prints it into your console |
|---|---|
| Used on | |
| Code | print( file.Read("../materials/vgui/sandbox.vmt") ) |
| Output | The contents of sandbox.vmt in your console. ![]() |
Additional Notes
- The filepath starts in the data folder. To read a file outside the data folder it must begin with ../, which means go up one folder.

