Lua比较特定目录下特定文件的MD5值
2013-11-27 13:13
323 查看
require"lfs"
require"md5"
function findindir (path, wefind, r_table, intofolder)
for file in lfs.dir(path) do
if file ~= "." and file ~= ".." then
local f = path.."\\"..file
--print ("\t "..f)
if string.find(f, wefind) ~= nil then
print("\t "..f)
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
for name, value in pairs(attr) do
print (name, value)
end
end
end
end
end
--比较两个文件的MD5--
function checkMD5(directory_new,directory_old)
local file_new = io.open(directory_new,"rb")
local file_old = io.open(directory_old,"rb")
local string_new = file_new:read("*a")
local string_old = file_old:read("*a")
if string_new ~= string_old then
print("please update your file")
print("The direffence between " ..directory_new.. " and " .. directory_old)
end
file_new:close()
file_old:close()
end
local currentFolder_new = [[D:\Luatest]]
local input_table_new = {}
local currentFolder_old = [[E:\Luatest]]
local input_table_old = {}
findindir(currentFolder_new, "%.txt", input_table_new, true)
findindir(currentFolder_old, "%.txt", input_table_old, true)
--for key, value in pairs(input_table_new) do
for i = 1, #(input_table_new) do
checkMD5(input_table_new[i],input_table_old[i])
i = i+1
end
require"md5"
function findindir (path, wefind, r_table, intofolder)
for file in lfs.dir(path) do
if file ~= "." and file ~= ".." then
local f = path.."\\"..file
--print ("\t "..f)
if string.find(f, wefind) ~= nil then
print("\t "..f)
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
for name, value in pairs(attr) do
print (name, value)
end
end
end
end
end
--比较两个文件的MD5--
function checkMD5(directory_new,directory_old)
local file_new = io.open(directory_new,"rb")
local file_old = io.open(directory_old,"rb")
local string_new = file_new:read("*a")
local string_old = file_old:read("*a")
if string_new ~= string_old then
print("please update your file")
print("The direffence between " ..directory_new.. " and " .. directory_old)
end
file_new:close()
file_old:close()
end
local currentFolder_new = [[D:\Luatest]]
local input_table_new = {}
local currentFolder_old = [[E:\Luatest]]
local input_table_old = {}
findindir(currentFolder_new, "%.txt", input_table_new, true)
findindir(currentFolder_old, "%.txt", input_table_old, true)
--for key, value in pairs(input_table_new) do
for i = 1, #(input_table_new) do
checkMD5(input_table_new[i],input_table_old[i])
i = i+1
end
相关文章推荐
- lua编程
- lua——函数
- Lua正则表达式
- Lua学习——闭包、迭代器
- mysql-proxy 按表分发查询的lua脚本
- Lua解析文件MD5
- 设计模式总结
- [译]简单声明Lua类
- lua2json
- 《Lua 5.0的实现》第八章 - 结论和致谢
- 《Lua 5.0的实现》第七章 - 虚拟机
- 《Lua 5.0的实现》第六章 - 线程和协程
- 《Lua 5.0的实现》第五章 - 函数和闭包
- lua——table 构造式
- LuaPlus上手指南
- lua table函数库
- lua string库函数
- lua 语言基础
- Lua语言中pairs和ipairs的区别
- 利用CEGUI+Lua实现灵活的游戏UI框架(转)