-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclean.py
More file actions
32 lines (26 loc) · 811 Bytes
/
clean.py
File metadata and controls
32 lines (26 loc) · 811 Bytes
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
import os
import shutil
EXCLUDED_DIRS = [
".venv",
".git",
] # exclude __pycache__ directories inside these folders
DIRS_TO_DELETE = ["__pycache__"]
def delete_folders(
folders: list = DIRS_TO_DELETE, exclude: list = EXCLUDED_DIRS, path: str = "."
) -> None:
print("Cleaning...")
for root, _, _ in os.walk(path):
try:
root_dir = root.split(os.sep)[1]
end_dir = root.rsplit(os.sep, 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)
print("Done.")