resource.addFile add directories and subdirectories?

hi, i need a simple script to add a directory and all its subdirectories to the download queue on my gmod server, and ive looked but couldn’t find a working script.
thanks

Ideally you should add the content to the workshop then use resource/AddWorkshop to add the download.

This is how I do it in my gamemode:

[lua]
function GM:SendResources( Directory, basedir )

basedir = basedir or self.ResourceDirectory

local files, folders = file.Find( basedir .. Directory .. "/*", "GAME" )

for k, v in pairs( files ) do
	if ( self:CheckResourceExtension( v ) ) then
		resource.AddFile( basedir .. Directory .. "/" .. v )
	end
end

for k, folder in pairs( folders ) do
	self:SendResources( Directory .. "/" .. folder, basedir )
end

end
[/lua]

The function is recursive. You enter a directory, and it adds all the files as resources, then it goes through the folders and calls itself with those folders as the argument. You won’t be able to just copy and paste this and have it work though, as it relies on other functions and variables, but hopefully this will give you enough information to attempt to write your own function.

i’m insanely stupid and can’t write anything
if it helps at all this is the code i’m using (which does nothing)


function addContentFolder( path )
        local files, folders = file.Find( path .. "/*", "GAME" )
        for k, v in pairs( files ) do
                resource.AddFile( path .. "/" .. v )
        end
        
        for k, v in pairs( folders ) do
                addContent( path .. "/" .. v )
        end
end

--Example:
addContentFolder( "sound/weapons" )

Clientside:



local function addfiles(path)
	local files, folders = file.Find(path.."*", "LUA")
	for _, v in pairs(files) do
		include(path..v)
	end

	for _, v in pairs(folders) do
		addfiles(path..v.."/")
	end
end
addfiles("yourgamemodename/gamemode/client/")
addfiles("yourgamemodename/gamemode/shared/")


Serverside:



local function addclientfiles(path)
	local files, folders = file.Find(path.."*", "LUA")
	for _, v in pairs(files) do
		AddCSLuaFile(path..v)
		print("Sent '"..path..v.."' to client.")
	end

	for _, v in pairs(folders) do
		addclientfiles(path..v.."/")
	end
end
addclientfiles("yourgamemodename/gamemode/client/")
addclientfiles("yourgamemodename/gamemode/shared/")

local function addserverfiles(path)
	local files, folders = file.Find(path.."*", "LUA")
	for _, v in pairs(files) do
		include(path..v)
		print("Included '"..path..v.."' serverside.")
	end

	for _, v in pairs(folders) do
		addserverfiles(path..v.."/")
	end
end
addserverfiles("yourgamemodename/gamemode/server/")


Should be pretty easy for you to figure out how to recode this, since its actually simple to code such an system.

what would be serverside and what would be clientside?
and i thought making clients download lua is pointless since gm13 syncs it with the client or something

[editline]29th September 2015[/editline]

nevermind, I’ll just use the LS linux function to list models/materials since it’s probably way easier. thanks anyway

Well you only need serverside, just use my serverside function and edit it abit.