Hello, i made a small script, that allow you to search for files in Subfolder too.
It return a table with all paths and filenames in the given folder and subfolders.
Very usefull for resource.AddFile()
file.GetRecrusiveFiles(string,table(optional))
For Example: file.GetRecursiveFiles("…/models/",{".mdl",".phy"})
models/alyx_animations.mdl
models/player/group03/male_08.mdl
models/player/group03/male_08.phy
Have Fun
[LUA]function file.GetRecursiveFiles(dir,filter)
local tbl = {}
local files = file.Find(dir…"")
local folders = file.FindDir(dir…"/")
local function DoFilter(filename)
if !filter then return true end
for k,v in pairs(filter) do
local len = string.len(v)
local extension = string.Right(filename,len)
if v == extension then return true end
end
return false
end
local function IsFolder(v)
if !folders then return false end
if table.HasValue(folders,v) then return true end
return false
end
if files then
for k,v in pairs(files) do
local str = string.lower(string.Right(v,5))
if str != “.ztmp” and !IsFolder(v) and DoFilter(v) then
local path = string.Replace(dir,"…/","")…v
table.insert(tbl,path)
end
end
end
if folders then
for k,folddir in pairs(folders) do
local filetbl = file.GetRecursiveFiles(dir…folddir…"/",filter)
for _,found in pairs(filetbl) do
table.insert(tbl,found)
end
end
end
return tbl
end
[/LUA]