-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathunique_files.py
More file actions
executable file
·48 lines (38 loc) · 1.09 KB
/
unique_files.py
File metadata and controls
executable file
·48 lines (38 loc) · 1.09 KB
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
48
#!/usr/bin python2
import os
import sys
import shutil
print "Enter folder to list all unique files: (Ex: /home/user/files)"
folderLoc= raw_input("Enter file location: ")
if not os.path.exists(folderLoc):
print "Folder doesn't exist"
sys.exit()
folderLoc2=folderLoc+'/duplicate_files'
if not os.path.exists(folderLoc2):
os.system("mkdir \""+ folderLoc2+"\"")
os.system("find -name '*.ASM' -print0 | xargs -0 md5sum | sort | uniq -Dw 32 > unique1.txt")
os.system("find -name '*.asm' -print0 | xargs -0 md5sum | sort | uniq -Dw 32 > unique2.txt")
with open("unique1.txt") as f1:
arr=[]
for line in f1:
a=line.split()
if a[0] not in arr:
arr.append(a[0])
else:
fname= a[1][2:]
source=folderLoc+ "/"+fname
destination=folderLoc+ "/duplicate_files"
shutil.move(source, destination)
with open("unique2.txt") as f1:
arr=[]
for line in f1:
a=line.split()
if a[0] not in arr:
arr.append(a[0])
else:
fname= a[1][2:]
source=folderLoc+ "/"+fname
destination=folderLoc+ "/duplicate_files"
shutil.move(source, destination)
os.remove("unique1.txt")
os.remove("unique2.txt")