#!/bin/bash # Process images in the specified directory process_images() { local target_dir="$1" mkdir "${target_dir}/RGB" mkdir "${target_dir}/MS" echo "Processing images in: $target_dir" for first_image in $(ls "$target_dir" | grep -E 'DJI_[0-9]{14}_[0-9]{4}_D\.JPG'); do echo "Found first image: $first_image" timestamp=$(echo "$first_image" | sed -E 's/DJI_([0-9]{14})_[0-9]{4}_D\.JPG/\1/') echo "Extracted timestamp: $timestamp" # Extract the number (XXXX) from the first image filename number=$(echo "$first_image" | sed -E 's/DJI_[0-9]{14}_([0-9]{4})_D\.JPG/\1/') echo "Extracted number: $number" mv "$target_dir/$first_image" "$target_dir/RGB/DJI-${timestamp}-${number}_D.JPG" for ext in "MS_G" "MS_NIR" "MS_R" "MS_RE"; do echo "Searching for matching ${ext}.TIF files with number: $number" image_to_rename=$(ls "$target_dir" | grep -E "DJI_[0-9]{14}_${number}_${ext}\.TIF" | head -n 1) if [ -n "$image_to_rename" ]; then new_ext=$(echo "${ext}" | sed 's/_//') new_name="DJI-${timestamp}-${number}_${new_ext}.TIF" echo "Renaming $target_dir/$image_to_rename to $target_dir/$new_name" mv "$target_dir/$image_to_rename" "$target_dir/MS/$new_name" else echo "No matching ${ext}.TIF files found for number: $number" fi done done } # Check if an argument is provided if [ $# -ne 1 ]; then echo "Usage: $0 " exit 1 fi # Call the function to process images process_images "$1"