【问题标题】:Loop through all the files in a directory with Corona and Lua使用 Corona 和 Lua 遍历目录中的所有文件
【发布时间】:2012-05-10 10:47:15
【问题描述】:

是否可以在 Corona SDK 中获取目录中所有文件的列表? 假设我有变量resourceDir = system.ResourceDirectory,我将如何遍历resourceDir 中的所有文件?

【问题讨论】:

标签: file filesystems lua coronasdk


【解决方案1】:

这个功能刚刚添加到 Corona 中,包括 LuaFileSystem 模块:

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

更多信息: http://blog.anscamobile.com/2012/05/luafilesystem-lfs-tutorial/

【讨论】:

    【解决方案2】:

    目前 Corona 不支持获取目录中的文件列表。有一个黑客使用 os.excute 发出“ls”命令,但事实证明它只适用于 Corona 模拟器,因为设备操作系统可能出于安全原因阻止了该功能。

    【讨论】:

      猜你喜欢
      • 2018-08-29
      • 2015-03-05
      • 1970-01-01
      • 2012-02-02
      • 2019-01-10
      • 2018-10-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多