Advertisement
mikematt1616

Improved walkdir for LuaRT

Feb 15th, 2021
401
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.84 KB | None | 0 0
  1. local sys = require("sys")
  2.  
  3. local function walkdir(dir, ext, recurse)
  4.     if type(dir) ~= "Directory" then
  5.         dir = sys.Directory(dir)
  6.     end
  7.     if type(ext) == "string" then ext = {ext} end
  8.     local entries = recurse or {}
  9.     for entry in each(dir) do    
  10.         if type(entry) == "File" then
  11.             if ext then
  12.                 for i = 1, #ext do
  13.                     if entry.filename:match(".%" .. ext[i] .. "$") then
  14.                         table.insert(entries, entry)
  15.                         entries[entry.fullpath] = entry
  16.                     end
  17.                 end
  18.             else
  19.                 table.insert(entries, entry)
  20.                 entries[entry.fullpath] = entry
  21.             end
  22.         else
  23.             entries = walkdir(entry, ext, entries)
  24.         end
  25.     end
  26.     return entries
  27. end
  28.  
  29. return walkdir
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement