Advertisement
Rochet2

Get files from a directory and subfolders (windows)

Aug 6th, 2014
372
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.48 KB | None | 0 0
  1. -- Get files from a directory and subfolders (windows)
  2.  
  3. local function scandir(path, files)
  4.     local f = io.popen('dir "'..path..'" /b')
  5.     if (not f) then return files end
  6.    
  7.     for name in f:lines() do
  8.         if (name:find("%.")) then
  9.             table.insert(files, path.."/"..name)
  10.         else
  11.             scandir(path.."/"..name, files)
  12.         end
  13.     end
  14.     f:close()
  15.     return files
  16. end
  17.  
  18. for k,v in ipairs(scandir("lua_scripts", {})) do
  19.     print(k, v)
  20. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement