lua跨平台文件夹遍历匹配查找
require"lfs" --[[Desc:在B路径D文件中下 搜寻A路径下的没用到的C类文件;
并且将没用到的B类文件名称打印出来;
设置好路径拖到lua自带编辑器中即可运行之;]]
--目标所在路径(A)(eg:png所在路径)
PNG_FILE_PATH = "E:/Resource/images"
--目标所寻路径(B)(eg:lua所在路径)
LUA_FILE_PATH = "E:/Resource/scripts" --搜寻目标后缀config(C)
SEARCH_TARGET = "%.png"
--查找目标后缀config(D)
FIND_TARGET = "%.lua" local pairs = pairs
function findindir (path, wefind, r_table, intofolder, fileType)
for file in lfs.dir(path) do
if file ~= "." and file ~= ".." then
local f = path..'/'..file
local fname = file;
if string.find(f, wefind) ~= nil then
if fileType == "png" then
table.insert(r_table, fname)
--print(fname);
elseif fileType == "lua" then
table.insert(r_table, f)
--print(f);
end
end
local attr = lfs.attributes (f)
assert (type(attr) == "table")
if attr.mode == "directory" and intofolder then
findindir (f, wefind, r_table, intofolder, fileType)
else
-- for name, value in pairs(attr) do
-- print (name, value)
-- end
end
end
end
end function isInIt( file,name )
for line in file:lines() do
if isContain(line , name) then
return true;
end
end
return false;
end function isContain( line , str )
return string.find(line , str);
end ----[[
local pngFilePath = PNG_FILE_PATH
local input_table_png = {}
findindir(pngFilePath, SEARCH_TARGET , input_table_png, true, "png") -- "%.png$"
print(#input_table_png);
--]] ----[[
local luaFilePath = LUA_FILE_PATH
local input_table_lua = {}
findindir(luaFilePath, FIND_TARGET , input_table_lua, true, "lua") -- "%.lua$"
print(#input_table_lua);
--]] ----[[
local count = ;
for _,imageName in pairs(input_table_png) do
local flag =
for _,fileName in pairs(input_table_lua) do
local fileInfo = io.open(fileName,"r")
if isInIt(fileInfo , imageName) then
flag = ;
break;
end
end
if flag == then
print("No Exist Image Name Is: "..imageName)
count = count + ;
end
end print("The File Count is:"..count);
----]]
lua文件lfs库可参见: http://keplerproject.github.io/luafilesystem/license.html
lua跨平台文件夹遍历匹配查找的更多相关文章
- lua使用io.open跨平台文件夹遍历匹配查找
-- Desc :实现在LUA_PATH中的lua文件中遍历寻找没用到PNG_PATH路径下的png图片,并将其打印出来. -- Date :12:49:28 2014-09-04 1 print(& ...
- HALCON初步:文件夹遍历,文件筛选,文件名拆分,图片读取及保存
[1]文件夹遍历 list_image_files ( : : ImageDirectory, Extensions, Options : ImageFiles) ImageDirectory: 文件 ...
- python学习笔记(六)文件夹遍历,异常处理
python学习笔记(六) 文件夹遍历 1.递归遍历 import os allfile = [] def dirList(path): filelist = os.listdir(path) for ...
- 编写Java程序,在一个文件夹内,查找占用磁盘空间最大的 jpg 文件,并输出文件大小
查看本章节 查看作业目录 需求说明: 在一个文件夹内,查找占用磁盘空间最大的 jpg 文件,并输出文件大小 实现思路: 创建ImageFileFilter类实现FilenameFilter接口,且重写 ...
- Android加载SD卡目录,文件夹遍历,图片设置,设置文件对应打开方式等
此案例主要说的是Android使用GridView加载SD卡下所有目录,文件夹多层遍历,文件图标修改,设置文件对应打开方式等功能. 如图: 代码: public class GridViewFile ...
- python实现文件夹遍历
python 中os.path模块用于操作文件或文件夹 os.path.exists(path) 判断文件路径是否存在 dir = "c:\windows"if os.path.e ...
- php 文件夹遍历俩种对比
configu.phpindex.php新建文件夹 D:\xampp\htdocs\1test\use\useversion/configu.phpD:\xampp\htdocs\1test\use\ ...
- Webpack 2 设置为从当前文件夹逐级向上查找模块
比较实用, 当你在cd到子文件夹运行webpack时,你可能想要require文件夹js里面的一些模块, 但你又想将祖先的js文件夹作为fallback.这样设置即可: module.exports ...
- python文件夹遍历,文件操作,获取文件修改创建时间
在Python中,文件操作主要来自os模块,主要方法如下: os.listdir(dirname):列出dirname下的目录和文件os.getcwd():获得当前工作目录os.curdir:返回当前 ...
随机推荐
- VIM的一些操作小技巧
vim的设计理念是:组合. 命令的组合,模式的组合, 普通模式 左: h 上:k 下:j 右 : l i : 当前光标处插入 I: 到光标所在行的行首进入插入模式 a: 在当前光标的后一位 ...
- Android Sqlite 工具类封装
鉴于经常使用 Sqlite 数据库做数据持久化处理,进行了一点封装,方便使用. 该封装类主要支持一下功能 支持多用户数据储存 支持 Sqlite数据库升级 支持传入 Sql 语句建表 支持 SQLit ...
- “ORA-01033:ORACLE initialization or shutdown in progress”错误的解决
网页上显示以下错误信息: ORA-:ORACLE initialization or shutdown in progress 启动oracle数据库,有以下提示信息 Database mounted ...
- npm下载速度太慢
因为墙的原因导致下载速度过慢,解决方式就是使用国内镜像 使用淘宝的镜像 npm config set registry="http://registry.npm.taobao.org/&qu ...
- 241. Different Ways to Add Parentheses
241. Different Ways to Add Parentheses https://leetcode.com/problems/different-ways-to-add-parenthes ...
- [UCSD白板题] The Last Digit of a Large Fibonacci Number
Problem Introduction The Fibonacci numbers are defined as follows: \(F_0=0\), \(F_1=1\),and \(F_i=F_ ...
- <Oracle Database>数据字典
数据字典 数据字典是由Oracle服务器创建和维护的一组只读的系统表,它存放了有关数据库和数据库对象的信息,Oracle服务器依赖这些信息来管理和维护Oracle数据库. 数据字典分为两大类:一种是基 ...
- iOS开发零基础--Swift篇 循环
循环的介绍 在开发中经常会需要循环 常见的循环有:for/while/do while. 这里我们只介绍for/while,因为for/while最常见 for循环的写法 最常规写法 // 传统写法 ...
- android wifi 获取扫描结果
1.1 framework部分: 1.2 supplicant部分: hdd_cfg80211_scan_done_callback -> wlan_hdd_cfg80211_update_bs ...
- document.write 摘抄
页面载入过程中用实时脚本创建页面内容,以及用延时脚本创建本窗口或新窗口的内容.该方法需要一个字符串参数,它是写到窗口或框架中的HTML内容.这些字符串参数可以是变量或值为字符串的表达式,写入的内容常常 ...