- Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclear.py
41 lines (37 loc) · 1.67 KB
/
clear.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
32
33
34
35
36
37
38
39
40
41
importos
importshutil
importsys
fromcoloramaimportinit, Fore, Back
# Initialize colorama
init(autoreset=True)
defclear_folders(base_dir):
# Walk through the directory
has_error=False
executed=False
forroot, dirs, filesinos.walk(base_dir):
fordir_nameindirs:
# Check for 'out' and '.vs' folders
ifdir_name=='out'ordir_name=='.vs'ordir_name=='.vscode':
folder_path=os.path.join(root, dir_name)
executed=True
try:
shutil.rmtree(folder_path) # Remove the folder and all its contents
print(f"{Fore.GREEN}[Success] Removing folder: {folder_path}")
exceptPermissionErrorase:
has_error=True
print(f"{Fore.RED}[Error] Removing folder: {folder_path} ------ ", end="")
print(f"{Fore.RED}Details: {e}")
return (nothas_error, executed)
if__name__=="__main__":
# base_directory = input("Enter the base directory to clear 'out/' '.vscode' and '.vs/' folders: ")
base_directory="./"
success, executed=clear_folders(base_directory)
ifsuccessandexecuted:
print("--------------------------------------------------")
print(f"{Fore.GREEN}Clearing complete. All out/ .vscode/ and .vs/ folders have been removed.")
elifsuccessandnotexecuted:
print(f"{Fore.YELLOW}No need to clear. No out/ .vscode/ or .vs/ folders found.")
else:
ifexecuted:
print("--------------------------------------------------")
print(f"{Fore.YELLOW}Clearing not complete. Some folders could not be removed.")