-
Notifications
You must be signed in to change notification settings - Fork 0
/
clean.py
31 lines (23 loc) · 788 Bytes
/
clean.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
28
29
30
31
import os
import shutil
EXCLUDED_DIRS = [
".venv",
".git",
] # exclude __pycache__ directories inside these folders
DIRS_TO_DELETE = ["__pycache__"]
def delete_folders(folders: list, exclude: list, path: str = ".") -> None:
for root, _, _ in os.walk(path):
try:
root_dir = root.split("\\")[1]
end_dir = root.rsplit("\\", 1)[1]
if root_dir not in exclude and end_dir in folders:
print(root)
try:
shutil.rmtree(root)
except (PermissionError, FileNotFoundError):
pass
except IndexError: # root dir
pass
except Exception as e:
print(e)
delete_folders(folders=DIRS_TO_DELETE, exclude=EXCLUDED_DIRS)