-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfile-dedupe.py
27 lines (22 loc) · 1014 Bytes
/
file-dedupe.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
import os
import re
import time
# set the directory you want to start from
# note the forward-slash - this is the correct, cross-platform separator.
root_dir = "D:/recover"
working_list = []
unwanted = re.compile(r'(.*)(\.txt$|\.html$|\.h$|\.chm$|_dll$|_ocx$|\.ttf$|\.xml$|\.exe$|\.dll$|\.tff$|_exe$|_DLL$|_mui$|\.bat$|\.wim$|_MUI$|_sys$|\.java$|\.sqlite$|\.plist$|\.pf$|\.ico$|\.woff$|_expand$|_EXE$|\.ini$|\.cab$|\.reg)')
for dir_name, sub_dir_list, file_list in os.walk(root_dir):
print(f'Checking directory: {dir_name}')
for file in file_list:
if unwanted.search(file):
print(f'Unwanted File: {os.path.join(dir_name, file)} - deleting')
os.remove(os.path.join(dir_name, file))
continue
if file in working_list:
print(f'Deleting: {os.path.join(dir_name, file)}')
os.remove(os.path.join(dir_name, file))
else:
working_list.append(file)
# time.sleep(1)
print(working_list)