Created
September 29, 2012 14:42
-
-
Save cornernote/3804224 to your computer and use it in GitHub Desktop.
Minetest - Get Files in a Directory
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- 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