ask before deleting

This commit is contained in:
2024-10-23 11:56:21 +02:00
parent d6fe061776
commit 8ea758be21

View File

@@ -9,7 +9,7 @@ if [ ! -d "$folder_path" ]; then
exit 1
fi
# Find and delete all .Trash-1000 directories within the provided path
# Find all .Trash-1000 directories within the provided path
echo "Searching for .Trash-1000 folders in $folder_path..."
trash_folders=$(find "$folder_path" -type d -name ".Trash-1000")
@@ -21,12 +21,19 @@ else
echo "$trash_folders"
echo
# Loop through each found folder and delete it while displaying progress
while IFS= read -r folder; do
echo "Deleting folder: $folder"
rm -rf "$folder"
echo "Deleted $folder"
done <<< "$trash_folders"
# Ask for confirmation before deletion
read -p "Do you really want to delete all these folders? (y/n): " confirmation
echo "All .Trash-1000 folders have been deleted."
if [[ "$confirmation" == "y" || "$confirmation" == "Y" ]]; then
# Loop through each found folder and delete it while displaying progress
while IFS= read -r folder; do
echo "Deleting folder: $folder"
rm -rf "$folder"
echo "Deleted $folder"
done <<< "$trash_folders"
echo "All .Trash-1000 folders have been deleted."
else
echo "Deletion canceled."
fi
fi