Created
July 30, 2024 12:24
-
-
Save imandaliya/963603ddadae9f32494a3de0a95ce4fb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# this code for delete build directory from folder where file is run | |
# this will delete directory and more to Trash in MacOs | |
# WARNING : check directory before delete | |
import os | |
from send2trash import send2trash | |
def find_build_directories(root_dir): | |
build_dirs = [] | |
# Walk through the root directory | |
for dirpath, dirnames, filenames in os.walk(root_dir): | |
# Check if 'build' is a directory in the current path | |
if 'build' in dirnames: | |
build_dir = os.path.join(dirpath, 'build') | |
build_dirs.append(build_dir) | |
return build_dirs | |
def confirm_and_delete(directory): | |
while True: | |
user_input = input(f"Do you want to delete the build directory: {directory}? (y/n): ").strip().lower() | |
if user_input == 'y': | |
try: | |
send2trash(directory) | |
print(f'Successfully sent to trash: {directory}') | |
except Exception as e: | |
print(f'Error sending to trash: {directory}, {e}') | |
break | |
elif user_input == 'n': | |
print(f'Skipped deletion of: {directory}') | |
break | |
else: | |
print("Invalid input. Please enter 'y' or 'n'.") | |
# Get the current working directory | |
root_directory = os.getcwd() | |
print(f'Root: {root_directory}') | |
# Find all build directories | |
build_directories = find_build_directories(root_directory) | |
# Confirm and delete each build directory | |
for build_dir in build_directories: | |
print(f'Dir to delete: {build_dir}') | |
confirm_and_delete(build_dir) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment