File size: 2,621 Bytes
f53b096
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#!/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 "=========================================="