-- Desc :实现在LUA_PATH中的lua文件中遍历寻找没用到PNG_PATH路径下的png图片,并将其打印出来。
-- Date :12:49:28 2014-09-04
1 print("Lua Script Start") function getFileName( path )
len = string.len(PNG_PATH);
return string.sub(path, len+) --  remove "/"
end function isInIt( file,name )
--print(file .. " -- " .. name )
for line in io.lines(file) do
if isContain(line , name) then
return true;
end
end
return false;
end function isContain( line , str )
return string.find(line , str);
end PNG_PATH = "user/image"
getPngFileTable = io.popen('find * ' .. PNG_PATH) pngFileTable = {};
for file in getPngFileTable:lines() do
if string.find(file,"%.png$") then
fileName = getFileName(file);
print(fileName)
table.insert(pngFileTable,fileName);
end
end
print("png count is :"..#pngFileTable); LUA_PATH = "user/scripts"
getLuaFileInfo = io.popen('find * ' .. LUA_PATH)
luaFileTable = {};
for file in getLuaFileInfo:lines() do
if string.find(file,"%.lua$") then
--print(file)
table.insert(luaFileTable,file);
end
end local pairs = pairs
for _,name in pairs(pngFileTable) do
flag = ;
for _,file in pairs(luaFileTable) do
if isInIt(file , name) then
flag = ;
break;
end
end
if flag == then
print(name)
end
end print("Lua Script End!") --Desc: lua io.popen ([prog [, mode]])
--Starts program prog in a separated process and returns a file handle that
--you can use to read data from this program (if mode is "r", the default)
--or to write data to this program (if mode is "w").
--This function is system dependent and is not available on all platforms.

注:

1: io.popen()简易说明  Lua中,os.execute可以执行dos命令,但是返回的是系统状态码,默认输出

io.popen()也可以执行dos命令,但是返回一个文件。eg:

  local t = io.popen('svn help')

  local a = t:read("*all")   --a返回一个字符串,内容是svn help的内容

  如果想执行某命令或程序可选os.execute() , 如果还想捕捉该执行结果可用io.popen(),得到的是userdata数据类型;

  eg:复制文件 os.execute("copy" .. originalPath .. "," .. backupPath)

2: io.popen() 是跨平台的,却也跟系统有关,在windows下无法取得访问文件夹的权限,屡次尝试都没成功,liunx和mac下可以;

3: 目前还不得知,使用io.poen()遍历的png图片竟然会 遍历了两边,造成结果是一半为脏数据,记载此文时还在查找原因,不解啊;

lua使用io.open跨平台文件夹遍历匹配查找的更多相关文章

  1. lua跨平台文件夹遍历匹配查找

    require"lfs" --[[Desc:在B路径D文件中下 搜寻A路径下的没用到的C类文件: 并且将没用到的B类文件名称打印出来: 设置好路径拖到lua自带编辑器中即可运行之; ...

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

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

  3. java io流 对文件夹的操作

    java io流 对文件夹的操作 检查文件夹是否存在 显示文件夹下面的文件 ....更多方法参考 http://www.cnblogs.com/phpyangbo/p/5965781.html ,与文 ...

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

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

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

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

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

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

  7. python实现文件夹遍历

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

  8. io流处理文件夹复制功能(java代码)

    拷贝某个目录下得所有文件拷指定位置 思想归纳 首先我们需要做的先获取到资源文件夹路径,这里我们先在程序中写死,然后我们还需要一个目标文件夹就是你需要拷贝到哪里.有了这两个文件夹我就可以进行复制了 然后 ...

  9. 【JAVA】编程(6)--- 应用IO流拷贝文件夹(内含多个文件)到指定位置

    此程序应用了: File 类,及其常用方法: FileInputStream,FileOutputStream类及其常用方法: 递归思维: package com.bjpowernode.javase ...

随机推荐

  1. 【转】linux yum命令详解

    yum(全称为 Yellow dog Updater, Modified)是一个在Fedora和RedHat以及SUSE中的Shell前端软件包管理器.基於RPM包管理,能够从指定的服务器自动下载RP ...

  2. css3 风车旋转

    <style> .box{width:400px;height:400px;margin:100px auto;transition:1s;} .box div{width:180px;h ...

  3. C++builder中使用TScrollBox 以后,让scrollBox相应鼠标的上下滑动

    1.在窗口的事件里搜索 mouseWheel的方法 2.在.cpp文件里实现下面的代码 void __fastcall TForm1::mouseWheel(TObject *Sender, TShi ...

  4. zabbix中文乱码解决方法

    将windows下的字体文件Fonts\simkai.ttf上传到zabbix的WEB目录下的fonts目录下 修改zabbix的PHP配置 将原来的DejaVuSans更改成simkai vim / ...

  5. 轻松创建R语言函数包

    讲真,用R这么几年,始终未尝试过写自己的包,看来这就是我与真正程序员的差距了——编程习惯等于没有. 昨天一个偶然的机会想开始写自己的工具包,发现了前期教程的有一些过时.于是,写一个**windows* ...

  6. Ubuntu下设置(增加/删除)开机启动项

    As said above, you have to edit /etc/xdg/autostart/ and either: remove the NoDisplay=true lines; or ...

  7. ubuntu下面mysql,通过载入txt文件初始化数据表

    环境:ubuntu12.04   mysql(通过apt安装) (1)根据数据表中的属性列,对应在txt中构造记录(一行对应一条记录),不同属性之间通过tab键(以/root目录下构建的init.tx ...

  8. php 正则

    1.中括号 [0-9]匹配0-9 [a-z]匹配a-z小写字母 [A-Z]匹配A-Z大写字母 [a-zA-Z]匹配所有大小写字母 可以使用ascii来制定更多 2.量词 p+匹配至少一个含p的字符串 ...

  9. 转:linux coredump调试

    1 )如何生成 coredump 文件 ? 登陆 LINUX 服务器,任意位置键入 echo "ulimit -c 1024" >> /etc/profile 退出 L ...

  10. 积累一点ctf需要掌握的常见脚本知识

    1.暴力破解压缩包. 2.利用像素点还原图片. from PIL import Image import re if __name__ == '__main__': x = 887 //将像素点个数进 ...