Advertisement
promitheus_sal

tree.lua

Mar 23rd, 2022 (edited)
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.57 KB | None | 0 0
  1. --[[
  2. (C) PROMETHEUS TECHNLOGIES 2022
  3.  
  4. tree.lua v1.0
  5. Lua recursive directory printer
  6. ]]
  7. local dir
  8. if #arg==0 then
  9.     dir = shell.dir()
  10. else
  11.     dir = arg[1]
  12. end
  13.  
  14. if not fs.isDir(dir) then
  15.     printError("Not a directory")
  16. end
  17.  
  18. function recursiveList(d,i)
  19.     i = i or 0
  20.     for _,n in pairs(fs.list(d)) do
  21.         local sd = d..'/'..n
  22.         if fs.isDir(sd) then
  23.             print(string.rep("  ",i)..n..'/')
  24.             recursiveList(sd,i+1)
  25.         else
  26.             print(string.rep("  ",i)..n)
  27.         end
  28.     end
  29. end
  30.  
  31. recursiveList(dir,0)
  32.  
  33.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement