Created
July 30, 2023 16:44
-
-
Save mdrokz/ff1a531f6e25b62f17610b870644de98 to your computer and use it in GitHub Desktop.
delete target folders in your dir where you store all of your rust projects
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
#!/bin/bash | |
# Check if directory argument is provided | |
if [ -z "$1" ]; then | |
echo "Please provide a directory as an argument." | |
exit 1 | |
fi | |
# Create an array of directories | |
dirs=($(ls -d "$1"/*)) | |
# Target folder to delete | |
target_folder="target" | |
# Iterate over directories | |
for dir in "${dirs[@]}"; do | |
# Remove the trailing slash from the directory name | |
dir=${dir%/} | |
# Check if directory exists | |
if [ -d "$dir" ]; then | |
# Go inside the directory | |
cd "$dir" | |
# Check if target folder exists | |
if [ -d "$target_folder" ]; then | |
# Delete the target folder | |
rm -rf "$target_folder" | |
echo "Deleted $target_folder in $dir" | |
else | |
echo "$target_folder does not exist in $dir" | |
fi | |
# Go back to the parent directory | |
cd .. | |
else | |
echo "$dir does not exist" | |
fi | |
done | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment