码迷,mamicode.com
首页 > 其他好文 > 详细

lua遍历文件夹

时间:2014-10-04 14:28:26      阅读:400      评论:0      收藏:0      [点我收藏+]

标签:lua   遍历文件夹   

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, wefind, r_table, 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

lua遍历文件夹

标签:lua   遍历文件夹   

原文地址:http://blog.csdn.net/zwc2xm/article/details/39778329

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!