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

LuaFileSystem的更多相关文章

  1. LuaFileSystem学习心得

    LuaFileSystem(简称lfs)是一个用于lua进行文件訪问的库,和Lua版本号同步.且是跨平台的,在为lua安装lfs之前须要先安装luarocks, luarocks是一个用于安装lua库 ...

  2. nginx的luajit安装luarocks并安装luafilesystem

    nginx的luajit安装luarocks并安装luafilesystem by admin on -- :: in , 69次 标题有点绕口.我尽量把关键词都贴进去.之前因为自己的nginx安装了 ...

  3. 使用Ldoc给Lua生成文档

    Ldoc介绍 LDoc是一个Lua的文档生成工具,过去,比较常用的Lua生成文档的工具是LuaDoc,可惜作者自从2008年之后就再也没有发布过新的版本了,说明作者基本上已经放弃维护了.而LDoc则是 ...

  4. lua跨平台文件夹遍历匹配查找

    require"lfs" --[[Desc:在B路径D文件中下 搜寻A路径下的没用到的C类文件: 并且将没用到的B类文件名称打印出来: 设置好路径拖到lua自带编辑器中即可运行之; ...

  5. Centos6.7安装docker1.7.1

    Docker当前发布的最新版本已经到了1.11,其官网上针对Centos的的安装需求如下: Docker requires a -bit installation regardless of your ...

  6. centos6.7 安装Docker

      一.查看系统版本 [root@localhost ~]# cat /etc/redhat-release CentOS release 6.7 (Final) 二.安装EPEL 1.进入cento ...

  7. Nginx_Lua

    http://www.ttlsa.com/nginx/nginx-lua/ 1.1. 介绍ngx_lua – 把lua语言嵌入nginx中,使其支持lua来快速开发基于nginx下的业务逻辑该模块不在 ...

  8. Lua xavante WEB server实现xmlrpc服务器端

    xavante xavante是一个使用lua实现的遵守http1.1的web server,支持wsapi. 依赖库: xavante核心 -- lua, copas(纯lua编写,网络连接coro ...

  9. 虚拟化之lxc

    LXC 中文名称就是 Linux 容器工具,容器可以提供轻量级的虚拟化,以便隔离进程和资源,使用 LXC 的优点就是不需要安装太多的软件包,使用过程也不会占用太多的资源,本文循序渐进地介绍LXC的建立 ...

随机推荐

  1. linux命令学习(4):cd命令

    Linux cd 命令可以说是Linux中最基本的命令语句,其他的命令语句要进行操作,都是建立在使用 cd 命令上的.所以,学习Linux 常用命令,首先就要学好 cd 命令的使用方法技巧. 1. 命 ...

  2. DBeaver连接达梦数据库

    1.连接类型选择ODBC. 2.编辑驱动设置: 1)Class Name:dm.jdbc.driver.DmDriver 2)URL Template:jdbc:dm://{dbserver}/{da ...

  3. android.DataBindingUtil

    import android.databinding.DataBindingUtil import android.os.Bundle import android.support.v7.app.Ap ...

  4. day_5.07py

    正则:

  5. C - 食物链

    来源poj1182 动物王国中有三类动物A,B,C,这三类动物的食物链构成了有趣的环形.A吃B, B吃C,C吃A. 现有N个动物,以1-N编号.每个动物都是A,B,C中的一种,但是我们并不知道它到底是 ...

  6. SPL标准库-数据结构

    数据结构:栈 );] = ;] = ;var_dump($array); 来自为知笔记(Wiz)

  7. 浅析原生js模仿addclass和removeclass

    //判断有没有class hasClass(elements, cName) { return !!elements.className.match(new RegExp("(\\s|^)& ...

  8. html学习_html5 新增标签和属性

    html5 新增标签和属性 1.html发展历程(html有很多版本) 2.快捷键生成不同版本(html4.xhtml.html5) 文档类型不同.字符设定 3.常用新标签 (只有html5才识别的标 ...

  9. centos 断网

    不知道为什么.....开启服务后就是断线 查询 ip addr 故障状态 正常状态 配置中关闭网络管理 命令:chkconfig NetworkManager off 配置中开启网络管理 命令: ch ...

  10. Java并发编程的4个同步辅助类(CountDownLatch、CyclicBarrier、Semphore、Phaser)

    我在<jdk1.5引入的concurrent包>中,曾经介绍过CountDownLatch.CyclicBarrier两个类,还给出了CountDownLatch的演示案例.这里再系统总结 ...