How to add multiple files at once?

I have a question and I hope we can do it.
Here is an example code and i’m sure you will understand:
[lua]for k, v in pairs( file.Find(“materials/VDDR/*.vtf”) ) do
resource.AddFile( v )
end

for k, v in pairs( file.Find(“materials/VDDR/*.vmt”) ) do
resource.AddFile( v )
end[/lua]

So this is not working, but I am sure we can do something like that, anybody know how?
Cause i don’t feel like adding 200 files by hand.

Thank you.

All the file functions default to garrysmod/data. So you’ll want to add …/ to the beginning of those paths, to make it go up a level first.

The strings in the table are just the filename rather than the path, so you’d want

[lua]resource.AddFile(“materials/VDDR/”…v)[/lua]

Also, the first loop that goes through the VTFs is unnecessary - resource.AddFile will add associated filetypes as a convenience feature - when you add a VMT to the download list it’ll add the VTF with the same name.

Here’s a function I made that adds files recursively.

[lua]

function ta.AddFilesRecursive(root,path)
if file.IsDir(path…root) then
for _,v in ipairs(file.Find(path…root…"/*")) do ta.AddFilesRecursive(v,path…root…"/") end
else
resource.AddFile(string.gsub(path…root,"%.%./",""))
end
end

ta.AddFilesRecursive("…/sound/ta","")
[/lua]

Alright, thanks to both of you.

You should use **[Resource.AddSingleFile

http://wiki.garrysmod.com/favicon.ico](wiki.garrysmod.com/?title=Resource.AddSingleFile)** when adding files recursively.

I need to update the generator to make use of AddSingleFile.

Link

And done.