• AddDir function not working?
    6 replies, posted
I am using the AddDir function from the example on this page: [url]http://maurits.tv/data/garrysmod/wiki/wiki.garrysmod.com/index5809.html[/url] This is the exact code that's in my lua/autorun/server/downloads.lua file: [lua] function AddDir(dir) // Recursively adds everything in a directory to be downloaded by client local list = file.FindDir("../"..dir.."/*") for _, fdir in pairs(list) do if fdir != ".svn" then // Don't spam people with useless .svn folders AddDir(dir.."/"..fdir) end end for k,v in pairs(file.Find(dir.."/*", true)) do resource.AddFile(dir.."/"..v) end end AddDir("materials/vgui/ttt") [/lua] And this is the directory that I'm trying to have users download files from: [IMG]http://i.imgur.com/7o8FsU7.png[/IMG] The only problem is that it doesn't work. Users just don't download any files from that directory. There aren't any errors at all. Does anyone know what I'm doing wrong?
That's an outdated AddDir you've got there. file.Find replaced file.FindDir. And file.Find needs a second argument for the root folder.
[QUOTE=bobbleheadbob;42660376]That's an outdated AddDir you've got there. file.Find replaced file.FindDir. And file.Find needs a second argument for the root folder.[/QUOTE] So would it be this? [lua] function AddDir(dir) // Recursively adds everything in a directory to be downloaded by client local list = file.Find("../"..dir.."/*", "/garrysmod/") for _, fdir in pairs(list) do if fdir != ".svn" then // Don't spam people with useless .svn folders AddDir(dir.."/"..fdir) end end for k,v in pairs(file.Find(dir.."/*", true)) do resource.AddFile(dir.."/"..v) end end AddDir("materials/vgui/ttt") [/lua]
[url]http://wiki.garrysmod.com/page/file/Find[/url] [QUOTE][2] string path The path to look for the files and directories in. "GAME" Structured like base folder (garrysmod/), searches all the mounted content (main folder, addons, mounted games etc) "LUA" or "lsv" - All Lua folders (lua/) including gamesmodes and addons "DATA" Data folder (garrysmod/data) "MOD" Strictly the game folder (garrysmod/), ignores mounting.[/QUOTE]
[lua] function AddDir(dir) // Recursively adds everything in a directory to be downloaded by client local f,d = file.Find(dir.."/*", "GAME") for _, fdir in pairs(d) do if fdir != ".svn" then AddDir(dir.."/"..fdir) end end for k,v in pairs(f) do resource.AddFile(dir.."/"..v) end end AddDir("materials/vgui/ttt") [/lua]
[QUOTE=bobbleheadbob;42660642][lua] function AddDir(dir) // Recursively adds everything in a directory to be downloaded by client local f,d = file.Find(dir.."/*", "GAME") for _, fdir in pairs(d) do if fdir != ".svn" then AddDir(dir.."/"..fdir) end end for k,v in pairs(f) do resource.AddFile(dir.."/"..v) end end AddDir("materials/vgui/ttt") [/lua][/QUOTE] This worked, thanks.
Sorry to bump, but when I do the exact same thing, my server won't start.
Sorry, you need to Log In to post a reply to this thread.