Advertisement
FFGFlash

api/path

Sep 28th, 2021 (edited)
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.58 KB | None | 0 0
  1. local function merge(tbl1, tbl2)
  2.   for i,v in ipairs(tbl2) do table.insert(tbl1, v) end
  3.   return tbl1
  4. end
  5.  
  6. function getFiles(root, recursive)
  7.   local function helper(path)
  8.     local retVal = {}
  9.     local files = fs.list(path)
  10.     for _,file in ipairs(files) do
  11.       file = path.."/"..file
  12.       local isDir = fs.isDir(file)
  13.       if isDir and recursive then
  14.         merge(retVal, helper(file))
  15.       elseif not isDir then
  16.         file = string.gsub(file,root.."/","")
  17.         table.insert(retVal, file)
  18.       end
  19.     end
  20.     return retVal
  21.   end
  22.   return helper(root)
  23. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement