-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcleaner.py
More file actions
36 lines (28 loc) · 1.27 KB
/
cleaner.py
File metadata and controls
36 lines (28 loc) · 1.27 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
import shutil
directory_path = ""
def SearchAndDelete(root):
for root_directory, subdirs, files in os.walk(root):
for subdir in subdirs:
# Check if we are in system32 to avoid touching it
if 'system32' in root_directory.lower():
continue
if 'Windows' in root_directory.lower():
continue
if 'WinSxS' in root_directory.lower():
continue
if 'windows' in root_directory.lower():
continue
if 'winSxS' in root_directory.lower():
continue
# Check if the subdir name contains 'cache' or 'Cache'
if 'cache' in subdir or 'Cache' in subdir:
directory_path = os.path.join(root_directory, subdir)
print(f"Attempting to delete: {directory_path}")
try:
shutil.rmtree(directory_path)
print(f"Deletion successful: {directory_path}")
except PermissionError:
print(f"Cannot delete {directory_path}: resource is in use")
except Exception as e:
print(f"Error deleting {directory_path}: {e}")