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. C# 读写Excel的一些方法,Aspose.Cells.dll

    需求:现有2个Excel,一个7000,一个20W,7000在20W是完全存在的.现要分离20W的,拆分成19W3和7000. 条件:两个Excel都有“登录名”,然后用“登录名”去关联2个Excel ...

  2. python 读取配置文件方法

    #coding=utf8 import ConfigParser config = ConfigParser.ConfigParser() config.readfp(open(raw_input(& ...

  3. Linux CentOS中防火墙的关闭及开启端口

    注:CentOS7之前用来管理防火墙的工具是iptable,7之后使用的是Firewall 样例:在CentOS7上安装tomcat后,在linux本机上可以访问tomcat主页,http://ip: ...

  4. smartcrop.js 内容感知图像裁剪

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  5. ubuntu部署安装 MySQL 5.7

    安装 MySQL 5.7安装 MySQL 运行命令: apt-get -y install mysql-server mysql-client 你会被要求提供MySQL的root用户密码 : New ...

  6. 转载:浅析@PathVariable 和 @RequestParam

    在网上看了一篇很好的文章,讲的很清楚明了,说到了点子上(转自:https://blog.csdn.net/chuck_kui/article/details/55506723): 首先 上两个地址: ...

  7. STL 标准模板库

    <vector> 可变长的数组 Vector<int>v int是一个模板参数,这样传进来的都会是int V.push_back(a)将a传进v,且放在最后一个 V.clear ...

  8. php后台对接ios,安卓,API接口设计和实践完全攻略,涨薪必备技能

    2016年12月29日13:45:27    关于接口设计要说的东西很多,可能写一个系列都可以,vsd图都得画很多张,但是由于个人时间和精力有限,所有有些东西后面再补充   说道接口设计第一反应就是r ...

  9. C和C指针小记(一)-字符输入,函数,ASCII扩展表

    1.连续接收输入字符时 int ch; while(ch != EOF && ch != '\n') ch 为什么被声明为整形,我们不是需要用它来读取字符的嘛? 因为:EOF是一个整形 ...

  10. CHARACTER SET

    mysql> show tables; +-----------------+ | Tables_in_w0811 | +-----------------+ | t | | w_engine ...