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