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. android rom开发

    How to Build Android ROMs on Ubuntu 16.04https://www.digitalocean.com/community/tutorials/how-to-bui ...

  2. B - Is It A Tree?

    来源 hdu 1325 A tree is a well-known data structure that is either empty (null, void, nothing) or is a ...

  3. 夺冠概率|2012年蓝桥杯B组题解析第九题-fishers

    (17')夺冠概率 足球比赛具有一定程度的偶然性,弱队也有战胜强队的可能. 假设有甲.乙.丙.丁四个球队.根据他们过去比赛的成绩,得出每个队与另一个队对阵时取胜的概率表: 甲 乙 丙 丁 甲 - 0. ...

  4. HDOJ HDU 1850 Being a Good Boy in Spring Festival

    Description 一年在外 父母时刻牵挂 春节回家 你能做几天好孩子吗 寒假里尝试做做下面的事情吧 陪妈妈逛一次菜场 悄悄给爸爸买个小礼物 主动地 强烈地 要求洗一次碗 某一天早起 给爸妈用心地 ...

  5. MyEclipse中同时启动两个tomcat

    开发的时候,有些时候需要同时启动两个项目.首先配置tomcat,方法如下:(转载自:http://bendan123812.iteye.com/blog/1716789) 一.把Tomcat复制一份并 ...

  6. python-mysql数据库导表存excel后发邮件(实例2)

    需求:用户输入mysql数据库中某表名,将此表导入到excel中,将导出文件以邮件形式发出 设计思路: 1连接数据库 2读取表头(cur.description--获取表头,函数返回二维元组,采用列表 ...

  7. linux文件系统扩展属性

    翻译自man手册,水平有限,有错还望不吝指出.... 扩展属性是与文件和目录相关的name:value对,用来提供文件系统的一些附加功能,例如ACL.对文件或是目录拥有读权限的用户可以看到其扩展属性. ...

  8. python basic

    #遍历一个序列,很多传统语言过来的,习惯用下标遍历,Python中序列是可迭代的,直接for即可! colors=['red','green','blue','yellow'] for color i ...

  9. [development][tcp/ip][ids] 一个简单有参考价值的库 libnids

    libhtp 中的例子, 可以通过libnids快速使用. 或者可以快速的写个sniffer. 支持三个功能 ip分片重组, tcp乱序重排, 端口扫描发现. 工程: https://github.c ...

  10. [web][nginx] 初识nginx -- 使用nginx搭建https DPI解码测试环境

    环境 CentOS 7 X86 文档: https://nginx.org/en/docs/ 安装: [root@dpdk ~]# cat /etc/yum.repos.d/nginx.repo [n ...