加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

lua遍历文件夹

发布时间:2020-12-14 22:06:31 所属栏目:大数据 来源:网络整理
导读:require"lfs"function findindir (path,wefind,r_table,intofolder) for file in lfs.dir(path) do if file ~= "." and file ~= ".." then local f = path..''..file --print ("/t "..f) if string.find(f,wefind) ~= nil then --print("/t "..f) table.in
require"lfs"
function findindir (path,wefind,r_table,intofolder)
    for file in lfs.dir(path) do
        if file ~= "." and file ~= ".." then
            local f = path..''..file
            --print ("/t "..f)
            if string.find(f,wefind) ~= nil then
                --print("/t "..f)
                table.insert(r_table,f)
            end
            local attr = lfs.attributes (f)
            assert (type(attr) == "table")
            if attr.mode == "directory" and intofolder then
                findindir (f,intofolder)
            else
                --for name,value in pairs(attr) do
                --    print (name,value)
                --end
            end
        end
    end
end
local currentFolder = [[C:]]
-------------------------------------
local input_table = {}
findindir(currentFolder,"%.txt",input_table,false)--查找txt文件
i=1
while input_table[i]~=nil do
print(input_table[i])
i=i+1
end

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读