-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfolderdupe.lua
47 lines (39 loc) · 1.07 KB
/
folderdupe.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
require('lfs')
local output = io.open('list.txt', 'w+')
---[[ for time testing (also uncomment bottom)
local x = os.clock()
--for i = 1,100000 do
--]]
local file = ""
local foldertable = {}
function getdirandsize (pathtodir)
for folder in lfs.dir(pathtodir) do
if not folder:find('^%.') then
local f = pathtodir .. '/' .. folder
if lfs.attributes(f,'mode') == 'directory' then
local size = lfs.attributes(f,'size')
local key = folder .. '?' .. size
if foldertable[key] == nil then
foldertable[key] = {}
table.insert(foldertable[key],pathtodir)
else
table.insert(foldertable[key],pathtodir)
end
getdirandsize(f)
end
end
end
end
getdirandsize('.')
for key, value in pairs(foldertable) do
if #value ~= 1 then
local k1, k2 = key:match('(.*)?(%d*)')
file = file .. k1 .. ' ' .. k2 .. '\t' .. table.concat(value,'\t') .. '\n'
--print(k1 .. ' ' .. k2)
end
end
---[[ for time testing
--end
print(string.format("elapsed time: %.2f\n", os.clock() - x))
--]]
output:write(file)