file.Read not working correctly

I was working on some scripts when I discovered that I couldn’t get file.Read to work clientside, it would only ever return nil while it would work fine when running file.Read server side reading server side files.
To test this I was using file.Read to look for wire_version.txt which is present in both my client and the server in the data folder.

local test = file.Read(“wire_version.txt”)
if test == nil then print(“File not found”)
else print(test) end

When I run it in a lua file in \garrysmod\lua\autorun\server
it prints the correct wire_version (gm13-401-gf291c42) which is expected

Where as when I place the lua file in \garrysmod\lua\autorun\client
it prints File not found to the clients console.

I then later discovered that even Adv dupe 2 was throwing errors when trying to load/save dupes from the client however adv dupe 1 worked perfectly since it saved the files on the server. However whenever a client attempts to upload a folder from their client to the server it again throws errors since it’s calling file.Read to read the dupe.

I have no idea what is causing this and would really appreciate any ideas to why this might be happening.
Many thanks, Jophes.

Well, do you run the code in singleplayer? If yes, then there you go, singleplayer is you being the Server, there is no client, you have to download the gmod dedicated server locally and code on there.

Try file.Read with two arguments.

the 2nd argument aint needed, since its data by default, and the wiremod version file is in the data folder.

The code is running on a dedicated server, not in single player. And I can confirm what whitestar is saying.
(From gmod wiki)
function file.Read( filename, path )
if ( path == true ) then path = “GAME” end
if ( path == nil or path == false ) then path = “DATA” end <-- Defaults to data

local f = file.Open( filename, “r”, path )
if ( !f ) then return end
local str = f:Read( f:Size() )
f:Close()
return str or “”
end

Jophes, for code please use the code tags example:



if blah then
    blah
end


also, if you use file.read clientside, you only print to the given clients console, not the server one, you dont read ALL clients file, only a specific client file(except using a for loop)

I understand that it would only print to the clients console and I understand how the file system works, I have used it before. I only created this code to confirm my suspicion that file.read was returning only nil values when running on the client because recently the add-ons on the server that were using file.read on the client side had suddenly broken. Clearly everyone has misunderstood my problem and I’ll just go about finding my own solution.

file.Read() works fine for me though.