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. 简单的dp

    有趣的数:(动态规划,状态转移) #include<stdio.h> ][]; int main() { int n,i; ; i<; i++) dp[i][]=; while(~s ...

  2. vim的批量注释与删除注释

    vim的批量注释与删除注释 方法一:块选择模式 批量注释: Ctrl + v 进入块选择模式,然后移动光标选中你要注释的行,再按大写的I进入行首插入模式输入注释符号如 // 或 #,输入完毕之后,Vi ...

  3. flashftp连接虚拟机centos报错的解决方法

    flashftp连接虚拟机centos报错,一般情况可能是因为端口(22)的权限没有开放 先在centos中检查并开放22端口,执行:iptables -I INPUT -p tcp --dport ...

  4. 前端模板Juicer

    Juicer 是一个高效.轻量的前端 (Javascript) 模板引擎,使用 Juicer 可以是你的代码实现数据和视图模型的分离(MVC). 除此之外,它还可以在 Node.js 环境中运行. 用 ...

  5. CodeForces 743C Vladik and fractions (数论)

    题意:给定n,求三个不同的数满足,2/n = 1/x + 1/y + 1/z. 析:首先1是没有解的,然后其他解都可以这样来表示 1/n, 1/(n+1), 1/(n*(n+1)),这三个解. 代码如 ...

  6. Ubuntu 中 不显示WIFI解决方法

    先用有线接到网络,打开终端,执行以下命令sudo apt-get update sudo apt-get install --reinstall bcmwl-kernel-source 执行成功即可看 ...

  7. 第59讲:Scala中隐式转换初体验

    今天学习了下隐式转换的内容.所谓隐式转换,就是说,一个实例拥用1 2 3方法,但是当它需要4方法的时候,它没有,但是却可以通过转换成另一种类型来调用4方法,而且这种转换是自动转换不需要人为干预的,这种 ...

  8. [转] How to change font settings for all UI elements (toolbar and context menus, property editors, etc.)

    https://www.devexpress.com/Support/Center/Question/Details/S35762

  9. Linq to Sql 聚合查询

    //输出体重最大的同学,并要求最大体重得大于39,并按照体重大下,对分组结果进行排序. var result = from query in linq.Student group query by q ...

  10. Execution Order of Event Functions

    In Unity scripting, there are a number of event functions that get executed in a predetermined order ...