getList 遍历文件
--遍历文件
function getList(path)
    local a = io.popen("ls "..path);
    local f = {};
    for l in a:lines() do
        table.insert(f,l)
    end
    a:close()
    return f
end
| 参数 | 类型 | 必填 | 说明 | 
|---|---|---|---|
| path | string | 是 | 要遍历文件的文件夹的路径 | 
| 返回值 | 类型 | 说明 | 
|---|---|---|
| list | table/nil | 文件路径的集合 | 
函数用例
如要列举触动精灵 lua 文件夹下所有的脚本文件,则输入:
--遍历文件
function getList(path)
    local a = io.popen("ls "..path);
    local f = {};
    for l in a:lines() do
        table.insert(f,l)
    end
    a:close()
    return f
end
list = getList(userPath().."/lua/");
if #list > 0 then
    for  i=1, #list,1  do
        dialog(list[i])
    end
else
    dialog("文件夹路径不存在")
end