-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDuplicateremover.py
More file actions
47 lines (41 loc) · 1 KB
/
Duplicateremover.py
File metadata and controls
47 lines (41 loc) · 1 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
import os,sys,re;
def checkext(f):
def g():
if len(sys.argv)<3:
print("Enter atleast one extension..")
if len(sys.argv)<2:
print("Enter Directory..")
return
f()
return g
def regex(str):
if not str:
return None
return re.match(r'.+\(\d+\).*',str)
def stripNum(str):
if not str:
return Nonesh
start=re.search(r'\(\d+\).*',str)
return str if not start else str[:start.start()]
@checkext
def main():
duplicates=[]
for file in os.listdir(sys.argv[1]):
for extension in sys.argv[2:]:
if file.endswith("."+extension):
str=file.rsplit(".",1)[0]
if regex(str):
print(str)
str=stripNum(str).strip()
print(str)
if str in duplicates:
check=input(f"Enter y to delete {str}\n").lower()
if check in ('y','yes'):
sys.argv[1]=sys.argv[1].strip("/")
os.remove(sys.argv[1]+"/"+file)
# os.rename(file,sys.argv[1]+"/"+stripNum(str)+"."+extension)
else:
duplicates.append(str)
print("Removed duplicates\n")
if __name__ == '__main__':
main()