lua遍历文件

来源:互联网 发布:苹果软件开发前景 编辑:程序博客网 时间:2024/06/05 12:43

主要是利用这个luaforwindows的这个软件来执行下面这些代码,把遍历目录得到的每一个路径都存在一个table里面,然后遍历这个table就能把每条目录都打印出来



--dofile("c:\\Users\\Amber\\Desktop\\a.lua")require "lfs"function getpathes(rootpath, pathes)    pathes = pathes or {}    ret, files, iter = pcall(lfs.dir, rootpath)    if ret == false then        return pathes    end    for entry in files, iter do        local next = false        if entry ~= '.' and entry ~= '..' then            local path = rootpath .. '/' .. entry            local attr = lfs.attributes(path)            if attr == nil then                next = true            end            if next == false then                 if attr.mode == 'directory' then                    getpathes(path, pathes)                else                    table.insert(pathes, path)                end            end        end        next = false    end        return pathesendpathes = {}pathes = getpathes("c:/Users/Amber/Desktop/src", pathes)for key, path in pairs(pathes) do    print(key .. "==" .. path)end


0 0
原创粉丝点击