gs4d / delete_subfolders.sh
percool's picture
Add files using upload-large-folder tool
f53b096 verified
#!/bin/bash
# Script to delete all subfolders except dr1.0_thr0.01_vmax_contrib in 000-* folders
# Usage: ./delete_subfolders.sh [--dry-run]
BASE_DIR="/data/dataset/objaverseBG_360_3deg_mosca_graph_model"
KEEP_FOLDER="dr1.0_thr0.01_vmax_contrib"
DRY_RUN=true
# Check if --dry-run flag is provided
if [ "$1" == "--dry-run" ] || [ "$1" == "-n" ]; then
DRY_RUN=true
echo "=== DRY RUN MODE - No files will be deleted ==="
echo ""
elif [ "$1" == "--execute" ] || [ "$1" == "-e" ]; then
DRY_RUN=false
echo "=== EXECUTION MODE - Files will be deleted ==="
echo ""
else
echo "=== DRY RUN MODE (default) - No files will be deleted ==="
echo "Use --execute or -e to actually delete files"
echo ""
fi
# Find all 000-* folders
cd "$BASE_DIR" || exit 1
folders_to_process=$(find . -maxdepth 1 -type d -name "000-*" | sort)
if [ -z "$folders_to_process" ]; then
echo "No folders matching pattern 000-* found."
exit 0
fi
total_deleted=0
total_folders_processed=0
# Process each 000-* folder
while IFS= read -r folder; do
folder_path="$BASE_DIR/$folder"
mono_path="$folder_path/mono"
# Check if mono subdirectory exists
if [ ! -d "$mono_path" ]; then
echo "Skipping $folder: mono/ subdirectory not found"
continue
fi
total_folders_processed=$((total_folders_processed + 1))
echo "Processing: $folder"
# Find all subfolders in mono/ except the one to keep
subfolders=$(find "$mono_path" -maxdepth 1 -type d ! -path "$mono_path" ! -name "$KEEP_FOLDER" | sort)
if [ -z "$subfolders" ]; then
echo " No subfolders to delete in $folder/mono/"
echo ""
continue
fi
# Count and list subfolders to delete
count=0
while IFS= read -r subfolder; do
count=$((count + 1))
subfolder_name=$(basename "$subfolder")
echo " [$count] Would delete: $folder/mono/$subfolder_name"
if [ "$DRY_RUN" = false ]; then
rm -rf "$subfolder"
fi
done <<< "$subfolders"
total_deleted=$((total_deleted + count))
echo " Total subfolders in this directory: $count"
echo ""
done <<< "$folders_to_process"
echo "=========================================="
echo "Summary:"
echo " Folders processed: $total_folders_processed"
echo " Subfolders to delete: $total_deleted"
if [ "$DRY_RUN" = true ]; then
echo " Mode: DRY RUN (no files deleted)"
echo ""
echo "To actually delete, run: $0 --execute"
else
echo " Mode: EXECUTION (files deleted)"
fi
echo "=========================================="