Lua比较特定目录下特定文件的MD5值



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
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值