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
lua的文件管理的更多相关文章
- LuaFileSystem
bokeyuan_1234 lua的文件管理 lua没有自己的文件管理 只有读取和写入文件,但是可以通过调用lfs(LuaFileSystem),lfs是一个 用于lua进行文件访问的库,支持lua5 ...
- lua unit test introduction
Unit Test Unit testing is about testing your code during development, not in production. Typically y ...
- Lua 学习笔记(一)环境搭建
Lua是一个小巧的脚本语言.Lua由标准C编写而成,代码简洁,几乎在所有的操作系统和平台上都可以编译,运行. 主要讲一下mac和win下的环境搭建. 工具: 1.Sublime Text 2 ...
- visual studio Lua 调试
BabeLua是一款基于VS (简称VS)的免费开源的Lua集成开发环境,在Lua编辑和调试方面,具有如下功能和特性: ●Lua语法高亮 ●语法检查 ●自动补全 ●一键注释 ●格式化代码 ●自定义代码 ...
- 使用BabeLua3.x在cocos2d-x中编辑和调试Lua
BabeLua是一款基于VS2012/2013的Lua集成开发环境,具有Lua语法高亮,语法检查,自动补全,快速搜索,注入宿主程序内对Lua脚本进行调试,设置断点观察变量值,查看堆栈信息等功能. 如何 ...
- OpenResty / Nginx模块,Lua库和相关资源的列表
OpenResty / Nginx模块,Lua库和相关资源的列表 什么是OpenResty OpenResty是一个成熟的网络平台,它集成了标准的Nginx核心,LuaJIT,许多精心编写的Lua库, ...
- Linux安装LAMP开发环境及配置文件管理
Linux主要分为两大系发行版,分别是RedHat和Debian,lamp环境的安装和配置也会有所不同,所以分别以CentOS 7.1和Ubuntu 14.04做为主机(L) Linux下安装软件,最 ...
- lua执行字节码的过程介绍
前面一篇文章中介绍了lua给下面代码生成最终的字节码的整个过程,这次我们来看看lua vm执行这些字节码的过程. foo = "bar" local a, b = "a& ...
- lua 学习笔记(1)
一.lua函数赋值与函数调用 在lua中函数名也是作为一种变量出现的,即函数和所有其他值一样都是匿名的,当要使用某个函数时,需要将该函数赋值给一个变量,这样在函数块的其他地方就可以通过 ...
随机推荐
- Church 整数前驱的推导
Church 整数前驱的推导比其后继复杂得多,wiki中一个前驱的定义据王垠的博客里说,是他一个数学系的同学花一星期时间推导出来的, 其定义确实比其它介绍lambda的文章中用pair来实现(据说是图 ...
- Android设计和开发系列第二篇:Action Bar(Design)
Action Bar The action bar is a dedicated piece of real estate at the top of each screen that is gene ...
- 【llinux】yum命令出现Loaded plugins: fastestmirror Determining fastest mirrors
在进行yum 安装的时候.报错了. Loaded plugins: fastestmirror Determining fastest mirrors fastestmirror是yum的一个加速插件 ...
- 响应式web设计之@media
两种方式,一种是直接在link中判断设备的尺寸,然后引用不同的css文件: 1 <link rel="stylesheet" type="text/css" ...
- python基础---->python的使用(四)
这里记录一下python关于网络的一些基础知识.不知为何,恰如其分的话总是姗姗来迟,错过最恰当的时机. python中的网络编程 一.socket模板创建一个 TCP 服务器 import socke ...
- 高效使用github
下面两个资料是我在github上面整理出来的repo,不断进行更新,将遇到的有帮助的文章尽量整理到上面,方便初学者也方便回顾学习.如果恰好你也有一些资料文章,欢迎fork - modify - pul ...
- 异构GoldenGate 12c 单向复制配置(支持DDL复制)
1.开始配置OGG支持DDL复制(在source端操作) 1.1 赋予权限 SQL> conn /as sysdba 已连接. SQL> grant execute on utl_file ...
- sencha touch 评分扩展
原版 :https://market.sencha.com/extensions/sencha-touch-2-rating-star-field 效果: 我的改造版(只是类名变了): Ext.def ...
- php应用
1. php判断是否为数字 is_numeric() 这个函数就是检测参数是否为数字,如果是就返回true,如果不是就返回false is_numeric( 'abcd123' ) or die('提 ...
- jenkins或ansible启动应用不成功日志又不报错
碰到ansible无法起停tomcat的时候,有3个点需要关注 1.环境变量,在startup.sh中添加source /etc/profile 2.后台运行,加上nohup...& 3.单独 ...