#!/bin/bash

# Enable nullglob so the array is empty if no files match
shopt -s nullglob

# Create an array matching both .bsp and .nav files containing "hxi"
FILES=(*hxi*.bsp *hxi*.nav *hxi*.dds *hxi*.txt)

# Check if the array is empty
if [ ${#FILES[@]} -eq 0 ]; then
    echo "Error: No .bsp or .nav files containing 'hxi' were found."
    exit 1
fi

echo "Found ${#FILES[@]} files to compress..."

# Loop through each file and compress it individually
for file in "${FILES[@]}"; do
    # -z : Compress (this is the default action)
    # -v : Verbose (shows the compression ratio)
    bzip2 -zvk "$file"
done

echo "Success! All files have been individually compressed."
