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跨平台文件夹遍历匹配查找的更多相关文章

  1. lua使用io.open跨平台文件夹遍历匹配查找

    -- Desc :实现在LUA_PATH中的lua文件中遍历寻找没用到PNG_PATH路径下的png图片,并将其打印出来. -- Date :12:49:28 2014-09-04 1 print(& ...

  2. HALCON初步:文件夹遍历,文件筛选,文件名拆分,图片读取及保存

    [1]文件夹遍历 list_image_files ( : : ImageDirectory, Extensions, Options : ImageFiles) ImageDirectory: 文件 ...

  3. python学习笔记(六)文件夹遍历,异常处理

    python学习笔记(六) 文件夹遍历 1.递归遍历 import os allfile = [] def dirList(path): filelist = os.listdir(path) for ...

  4. 编写Java程序,在一个文件夹内,查找占用磁盘空间最大的 jpg 文件,并输出文件大小

    查看本章节 查看作业目录 需求说明: 在一个文件夹内,查找占用磁盘空间最大的 jpg 文件,并输出文件大小 实现思路: 创建ImageFileFilter类实现FilenameFilter接口,且重写 ...

  5. Android加载SD卡目录,文件夹遍历,图片设置,设置文件对应打开方式等

    此案例主要说的是Android使用GridView加载SD卡下所有目录,文件夹多层遍历,文件图标修改,设置文件对应打开方式等功能. 如图: 代码: public class GridViewFile ...

  6. python实现文件夹遍历

    python 中os.path模块用于操作文件或文件夹 os.path.exists(path) 判断文件路径是否存在 dir = "c:\windows"if os.path.e ...

  7. php 文件夹遍历俩种对比

    configu.phpindex.php新建文件夹 D:\xampp\htdocs\1test\use\useversion/configu.phpD:\xampp\htdocs\1test\use\ ...

  8. Webpack 2 设置为从当前文件夹逐级向上查找模块

    比较实用, 当你在cd到子文件夹运行webpack时,你可能想要require文件夹js里面的一些模块, 但你又想将祖先的js文件夹作为fallback.这样设置即可: module.exports ...

  9. python文件夹遍历,文件操作,获取文件修改创建时间

    在Python中,文件操作主要来自os模块,主要方法如下: os.listdir(dirname):列出dirname下的目录和文件os.getcwd():获得当前工作目录os.curdir:返回当前 ...

随机推荐

  1. bootstrap 模态框禁用空白处点击关闭

    bootstrap 3 模态框为信息编辑窗口,默认点击空白处会自动关闭,但是有的时候这个功能需要关闭,比如编辑信息,一不小心点击了空白处,那就要重新编辑了. bootstrap 3 模态框禁用空白处点 ...

  2. Red Hat Enterprise Server 5.8+oracle10g(中文界面)安装

    Red Hat Enterprise Server 5.8+oracle10g(中文界面)安装 VMware workstation10(虚拟机)下面安装红帽企业版5.8 创建虚拟机 新建虚拟机,选择 ...

  3. Catia CAA 二次开发 ---- 开发准备(0)

    去年开始学习Catia CAA的二次开发,前后的间断性学习有1年吧. 现在已经好久没用,忘得也差不多了,原来的笔记都放在了Evernote,现在还是觉得边继续复习边总结一下,以后也比较好检索. 先吐槽 ...

  4. 基于Axure的快速原型方法

    Axure是一个专业的快速原型设计工具,让负责定义需求和规格.设计功能和界面的专家能够快速创建应用软件或Web网站的线框图.流程图.原型和规格说明文档.作为专业的原型设计工具,它能快速.高效的创建原型 ...

  5. MongoDB初步(一)

    1.软件下载:mongodb-win32-x86_64-2008plus-ssl-3.4.1-signed.msi 2.下载补丁:hotfix kb2731284

  6. 百度音乐api

    百度音乐全接口 会利用使用接口找歌简单又快捷 http://tingapi.ting.baidu.com/v1/restserver/ting 获取方式:GET 参数:format=json或xml& ...

  7. Select loop

    The Bash Shell also offer select Loop, the syntax is: select varName in list do command1 command2 .. ...

  8. JAVA 求和程序

  9. 【MySQL】事务没有提交导致 锁等待Lock wait timeout exceeded异常

    异常:Lock wait timeout exceeded; try restarting transaction 解决办法:(需要数据库最高权限) 执行select * from informati ...

  10. (转)Windows下的Memcached安装与使用

    WHAT Memcached 是一个高性能的分布式内存对象缓存系统,用于动态Web应用以减轻数据库负载.它通过在内存中缓存数据和对象来减少读取数据库的次数,从而提高动态.数据库驱动网站的速度.Memc ...