Loop through all the files in a directory with Corona and Lua
Is it possible in Corona SDK to get a list of all the files in a directory?
Say I have variable开发者_StackOverflow社区 resourceDir = system.ResourceDirectory
, how would I loop through all the files in resourceDir?
This functionality has just been added with Corona including the LuaFileSystem module:
local lfs = require "lfs"
local doc_path = system.pathForFile( "", system.DocumentsDirectory )
for file in lfs.dir(doc_path) do
-- file is the current file or directory name
print( "Found file: " .. file )
end
More info: http://blog.anscamobile.com/2012/05/luafilesystem-lfs-tutorial/
Currently Corona doesn't support getting a list of files in a directory. There was a hack that used os.excute to issue a "ls" command but it turns out that only works in the Corona Simulator because the device OS is probably blocking the feature for security reasons.
精彩评论