file.Read

From GMod Wiki

Jump to: navigation, search
Function
Syntax file.Read( String filepath )
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
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

DescriptionThis 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 )
OutputNone.


DescriptionReads one of the stock vmt files and prints it into your console
Used on
Code
print( file.Read("../materials/vgui/sandbox.vmt") )
OutputThe contents of sandbox.vmt in your console.
File:File.Read1.jpg


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.

See Also

Personal tools