file.Read/Write limited?

I’m having a small issue with writing a file to the data folder.
file.Write(“testing.txt”, “bumble”)
The above code writes a file to the directory garrysmod/data. Thus being garrysmod/data/testing.txt
This above code reads the file and all of its content of garrysmod/data/testing.txt, Nothing wrong is there.

Now, what if we want to write a file to the garrysmod/gamemodes/myGamemode/content/data folder?

Answer: You can’t, not without a DLL anyway

However, you can read from the gamemodes/content/data directory just fine. Lets say you made a text file in garrysmod/gamemodes/myGamemode/content/data, called it “anothertest.txt” and inside the file put “bee”.

Then ran:
[lua]print( file.Read(“anothertest.txt”) )[/lua]
Your output in the console would be, “bee”.

So I ask, Why arn’t we allowed to write files to our gamemodes data folder, yet we can read it? I wanted to write to my gamemode folder to keep everything together, keep the data folder from becoming a mess. Which yeah people will say organize your files into different directories. But what if I want to release my gamemode? I’ll have to pack it into a rar and remove all the other text files which are not needed in the release or in any way related to the gamemode. Why can’t we just have the option/function to write to our gamemodes data folder?

You could try this [lua]file.Write("…/gamemodes/myGamemode/content/data/anothertest.txt", “bumble”)[/lua]

I think Gmod just copies everything in /garrysmod/gamemode/myGamemode/content into the the /garrysmod/ directory, so the fact you can read /garrysmod/gamemode/myGamemode/content/data is just an accident. Same thing would probably happen if you put something in /garrysmod/addons/myAddon/data.

On my side that doesn’t work MakeR, it doesn’t even write to the garrysmod/data folder either.

I believe you can’t read/write anything outside the data folder. Both pages state this.

I suspect gmod mounts everything in garrysmod/gamemodes/myGamemode/content/ into garrysmod/, so as far as source knows the data folder inside the gamemode is the same as the data folder in the root. I could be wrong though…


My simple anticheat scans their Lua folder when people join my server. There are no restrictions against reading Lua files outside of the Data directory as far as I can tell.

u can use read becouse then an lua coder can check if users have files like wire or phx, or even make plugin systems at gamemode’s or what ever u want to do.

u cant write outside the data becouse else some bitch would make a script that spams ur hole Gmod folder full whit crappy textfiles or even ur C:\ or ur desktop.

Anymore to say?

It’s obviously not meant to catch anyone who knows what they’re doing.

Why yes obviously. What about the people that download the scripts to bypass it? I guess they definitely know what they’re doing too.

But besides, leave that for the anti cheat thread. Isn’t is some way possible to write files to just the gamemode/content/data folder?