-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlist.py
37 lines (31 loc) · 1.33 KB
/
list.py
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
import argparse
import os
from pathlib import Path
#from duplicatehandler.duplicatehandler import PrintDuplicateHandler
from duplicatehandler.sortedprintduplicatehandler import SortedPrintDuplicateHanler
parser = argparse.ArgumentParser(description ='Lists duplicate files found by scan.py')
parser.add_argument('--hashes', dest='hashes', action='store', default='hashes.txt',
help='File containing hashes from scan.py.')
args = parser.parse_args()
def printLine(line:str):
(hash, size, filename) = line.split(' ', 2)
print(size + ' ' + filename.strip())
#duplicateHandlers = [PrintDuplicateHandler()]
duplicateHandlers = [SortedPrintDuplicateHanler()]
hashFilePath = args.hashes
with open(Path(hashFilePath), "r") as f:
lines = f.readlines()
lines.sort()
(prevHash, prevSize, prevFilename) = ('', '', '')
prevIsHandled = False
for line in lines:
(hash, size, filename) = line.split(" ", 2)
if (hash == prevHash):
if (not prevIsHandled):
[handler.handleDuplicate(prevHash, prevSize, prevFilename) for handler in duplicateHandlers]
prevIsHandled = True
[handler.handleDuplicate(hash, size, filename) for handler in duplicateHandlers]
else:
prevIsHandled = False
(prevHash, prevSize, prevFilename) = (hash, size, filename)
[handler.finished() for handler in duplicateHandlers]