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
LuaFileSystem的更多相关文章
- LuaFileSystem学习心得
LuaFileSystem(简称lfs)是一个用于lua进行文件訪问的库,和Lua版本号同步.且是跨平台的,在为lua安装lfs之前须要先安装luarocks, luarocks是一个用于安装lua库 ...
- nginx的luajit安装luarocks并安装luafilesystem
nginx的luajit安装luarocks并安装luafilesystem by admin on -- :: in , 69次 标题有点绕口.我尽量把关键词都贴进去.之前因为自己的nginx安装了 ...
- 使用Ldoc给Lua生成文档
Ldoc介绍 LDoc是一个Lua的文档生成工具,过去,比较常用的Lua生成文档的工具是LuaDoc,可惜作者自从2008年之后就再也没有发布过新的版本了,说明作者基本上已经放弃维护了.而LDoc则是 ...
- lua跨平台文件夹遍历匹配查找
require"lfs" --[[Desc:在B路径D文件中下 搜寻A路径下的没用到的C类文件: 并且将没用到的B类文件名称打印出来: 设置好路径拖到lua自带编辑器中即可运行之; ...
- Centos6.7安装docker1.7.1
Docker当前发布的最新版本已经到了1.11,其官网上针对Centos的的安装需求如下: Docker requires a -bit installation regardless of your ...
- centos6.7 安装Docker
一.查看系统版本 [root@localhost ~]# cat /etc/redhat-release CentOS release 6.7 (Final) 二.安装EPEL 1.进入cento ...
- Nginx_Lua
http://www.ttlsa.com/nginx/nginx-lua/ 1.1. 介绍ngx_lua – 把lua语言嵌入nginx中,使其支持lua来快速开发基于nginx下的业务逻辑该模块不在 ...
- Lua xavante WEB server实现xmlrpc服务器端
xavante xavante是一个使用lua实现的遵守http1.1的web server,支持wsapi. 依赖库: xavante核心 -- lua, copas(纯lua编写,网络连接coro ...
- 虚拟化之lxc
LXC 中文名称就是 Linux 容器工具,容器可以提供轻量级的虚拟化,以便隔离进程和资源,使用 LXC 的优点就是不需要安装太多的软件包,使用过程也不会占用太多的资源,本文循序渐进地介绍LXC的建立 ...
随机推荐
- Elasticsearch 学习之不停止服务,完成升级重启维护操作
我们可以设置集群的平衡参数来暂时禁用掉平衡,具体步骤如下: 1.如果可能的话,先暂停掉数据新增和更新操作,这样会提高集群恢复的时间: 2.禁用集群分片平衡操作,直到告诉集群可以恢复平衡操作为止,禁用配 ...
- C# Post HTTP Request
using System; using System.Collections.Generic; using System.IO; using System.Net; using System.Secu ...
- iOS - UILabel添加图片之富文本的简单应用
//创建富文本 NSMutableAttributedString *attri = [[NSMutableAttributedString alloc] initWithString:@" ...
- mysql的安装和配置
1.mydql的安装 重装wind7系统之后,mysql软件自动卸载了.现在学习需要使用mysql,还是要安装mysql.我首先通过下载安装包的方式安装,按照教程,但是出现缺失.dll文件,我下载安装 ...
- K - Super A^B mod C
Given A,B,C, You should quickly calculate the result of A^B mod C. (1<=A,C<=1000000000,1<=B ...
- 编译openssl失败(SLES11.3), undefined reference to `OPENSSL_cpuid_setup'
https://stackoverflow.com/questions/11381514/undefined-reference-when-compiling-openssl I ran into t ...
- day3 三、基本数据类型和运算符
一.多行注释和单行注释 """ 多行注释 多行注释 多行注释 """ # 单行注释 # print('hello world') # pri ...
- tsm 带库 磁带
磁带和存储池设置 新装入带库的磁带,需执行格式化命令方可使用,而存储池采用手工定义方式加入磁带,所以checkin状态设置为private,而不使用scratch磁带自动定义方式. label lib ...
- F#周报2019年第1期
新闻 介绍versionsof.net InfoQ正在寻找F#社区的声音 使用F#开发端对端的实际应用 UnoPlatform上的F# Elmish 视频及幻灯片 事件溯源DIY02--事件,事件存储 ...
- 泡泡一分钟:Motion Planning for a Small Aerobatic Fixed-Wing Unmanned Aerial Vehicle
Motion Planning for a Small Aerobatic Fixed-Wing Unmanned Aerial Vehicle Joshua Levin, Aditya Paranj ...