-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclonezapper.py
More file actions
executable file
·37 lines (32 loc) · 860 Bytes
/
clonezapper.py
File metadata and controls
executable file
·37 lines (32 loc) · 860 Bytes
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 os
import hashlib
def hashy(file):
hasher = hashlib.md5()
with open(file, 'rb') as afile:
buf = afile.read()
hasher.update(buf)
return hasher.hexdigest()
fileHashes = []
def checkIfAlreadyExists(hash):
if hash in fileHashes:
return True
else:
return False
deleted = 0
def shouldIDeleteThisFile(fileName):
global deleted
hash = hashy(fileName)
if checkIfAlreadyExists(hash):
os.remove(fileName)
print hash + ' : ' + fileName + ' - Deleted'
deleted += 1
else:
fileHashes.append(hash)
print hash + ' : ' + fileName + ' - Added to list'
totalNumberOfFiles = 0
for (dir, _, files) in os.walk(os.curdir):
for f in files:
path = os.path.join(dir, f)
totalNumberOfFiles += 1
shouldIDeleteThisFile(path)
print 'Finished. ' + str(deleted) + '/' + str(totalNumberOfFiles) + ' files were duplicates. They have been deleted.'