function getFilesRecursive(path, maxDepth, depth, storage)
-- vars
path = path or '.'
maxDepth = maxDepth or -1
depth = depth or 0
storage = storage or {}
-- validate maxDepth
if maxDepth ~= -1 and depth > maxDepth then
return storage
end
-- sanitize path leading "."
if not string.find(path, '^%.') then
path = '.' .. path
end
-- sanitize path leading double "//"
if string.find(path, '^%.//') then
path = string.gsub(path, '^%.//', './')
end
-- get dir/files
local files = dir(path)
-- validate files
if not files or (type(files) == 'table' and #files == 0) then
return storage
end
-- loop files
for _, file in ipairs(files) do
-- directory
if file.type == 'directory' then
getFilesRecursive(path .. '/' .. file.name, maxDepth, depth + 1, storage)
-- lua file
elseif string.find(file.name, '%.lua$') then
table.insert(storage, path .. '/' .. file.name)
end
end
return storage
end
function getFoldersRecursive(path, maxDepth, depth, storage)
-- vars
path = path or '.'
maxDepth = maxDepth or -1
depth = depth or 0
storage = storage or {}
-- validate maxDepth
if maxDepth ~= -1 and depth > maxDepth then
return storage
end
-- sanitize path leading "."
if not string.find(path, '^%.') then
path = '.' .. path
end
-- sanitize path leading double "//"
if string.find(path, '^%.//') then
path = string.gsub(path, '^%.//', './')
end
-- get dir/files
local files = dir(path)
-- validate files
if not files or (type(files) == 'table' and #files == 0) then
return storage
end
-- loop files
for _, file in ipairs(files) do
-- directory
if file.type == 'directory' then
table.insert(storage, path .. '/' .. file.name)
getFoldersRecursive(path .. '/' .. file.name, maxDepth, depth + 1, storage)
end
end
return storage
end