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 )

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

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


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.


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


Alright, thanks to both of you.

You should use **[Resource.AddSingleFile](** when adding files recursively.

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


And done.