Skip to content

Instantly share code, notes, and snippets.

@cornernote
Created September 29, 2012 14:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cornernote/3804224 to your computer and use it in GitHub Desktop.
Save cornernote/3804224 to your computer and use it in GitHub Desktop.
Minetest - Get Files in a Directory
-- return a table of filenames
get_files = function(directory)
local modpath = minetest.get_modpath("my_mod")
local output
if os.getenv('HOME')~=nil then -- linux/mac
os.execute('\ls -a "'..modpath..'/'..directory..'/" | grep .we > "'..modpath..'/'..directory..'/_files"')
local file, err = io.open(modpath..'/'..directory..'/_files', "rb")
if err ~= nil then
return
end
output = file:lines()
else -- windows
output = io.popen('dir "'..modpath..'\\'..directory..'\\*.we" /b'):lines()
end
local i, t = 0, {}
for filename in output do
i = i + 1
t[i] = filename
end
return t
end
print(dump(get_files()))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment