• LuaFileSystem


    lua的文件管理

    lua没有自己的文件管理 只有读取和写入文件,但是可以通过调用lfs(LuaFileSystem),lfs是一个

    用于lua进行文件访问的库,支持lua5.1和lua5.2,并且跨平台

    lfs的使用:

    "lfs" = {  --dump(lfs )
      "_COPYRIGHT"      = "Copyright (C) 2003 Kepler Project"
      "_DESCRIPTION"   = "LuaFileSystem is a Lua library developed to complement the set of functions   related to file systems offered by the standard Lua distribution"
      "_VERSION"      = "LuaFileSystem 1.4.2"
      "attributes"         = function: 00B3D7A8
      "chdir"                = function: 00B3D7C8
      "currentdir"      = function: 00B3D7E8
      "dir"         = function: 00B3D808
      "lock"         = function: 00B3D828
      "mkdir"         = function: 00B3D868
      "rmdir"       = function: 00B3D888
      "setmode"              = function: 00B3D8C8
      "symlinkattributes" = function: 00B3D8A8
      "touch"        = function: 00B3D908
      "unlock"      = function: 00B3D948
    }

    常用的方法:

    lfs.currentdir() --返回当前所在的全路径字符串

    lfs.attributes(dir) -- 返回文件的属性table

    lfs.dir(path)--用于遍历文件加中的对象

      

    复制代码
    --遍历
    function getAllFiles(path, files)
        files = files or {}
        for file in lfs.dir(path) do
            if file ~= "." and file ~= ".." then
                local subPath = path .. "\" .. file 
                local attr = lfs.attributes(subPath)
                assert(type(attr) == "table")
                if attr.mode == "directory" then
                    getAllFiles(subPath, files)
                else
                    table.insert(files, subPath)                                              
                end 
            end
        end
        return files
    end
    
    --查找
    function findInDir (path, wefind, r_table, intofolder)  
        for file in lfs.dir(path) do  
            if file ~= "." and file ~= ".." then  
                print(file)
                local f = path..'/'..file  
                if string.find(f, wefind) ~= nil then  
                    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  
    
                end  
            end  
        end  
    end
  • 相关阅读:
    css选择器中的*= , |= , ^= , $= , ~= 的区别
    css 实现小三角
    使用vitevue3ts快速上手做一个todolist
    什么是回流和重绘?
    vue好用组件推荐
    Vue代码风格及规范
    聊聊 SpringBoot 中的两种占位符:@*@ 和 ${*}
    Maven 依赖调解源码解析(三):传递依赖,路径最近者优先
    Maven 依赖调解源码解析(二):如何调试 Maven 源码和插件源码
    Maven 依赖调解源码解析(五):同一个文件内声明,后者覆盖前者
  • 原文地址:https://www.cnblogs.com/yanzi-meng/p/9273600.html
Copyright © 2020-2023  润新知