findFile 查找文件

--查找文件
function findFile(path)
    local a = io.popen("find "..path.." -prune");
    local f = {};
    for l in a:lines() do
        table.insert(f,l)
    end
    a:close()
    return f
end
参数 类型 必填 说明
path string 要查找文件的路径,支持 * 通配符
返回值 类型 说明
file table 返回所有查找到的文件路径集合

函数用例

如要查找 lua 文件夹下后缀为 .lua 的文件,则输入:

--查找文件
function findFile(path)
    local a = io.popen("find "..path.." -prune");
    local f = {};
    for l in a:lines() do
        table.insert(f,l)
    end
    a:close()
    return f
end
file = findFile(userPath().."/lu1a/*.lua")
if #file > 0 then
    for  i=1,#file,1  do
        dialog(file[i])
    end
else
    dialog("文件路径不存在")
end
Copyright 北京帮你玩科技有限公司 2023 all right reserved,powered by Gitbook该文章修订时间: 2024-03-06 17:50:18

results matching ""

    No results matching ""