Files
avdb-py/scripts/image_files_to_folders.sh
2026-10-04 18:24:18 -04:00

29 lines
789 B
Bash
Executable File

#!/bin/bash
# Directory containing the JPEG images
IMG_DIR="img"
# Check if the directory exists
if [ ! -d "$IMG_DIR" ]; then
echo "Directory $IMG_DIR does not exist."
exit 1
fi
# Loop through each JPEG file in the directory
for img_file in "$IMG_DIR"/*.jpg "$IMG_DIR"/*.jpeg; do
# Check if the file exists (to handle cases where no files match the pattern)
if [ -f "$img_file" ]; then
# Extract the base name of the file (without extension)
base_name=$(basename "$img_file" | cut -d. -f1)
# Create a folder with the same base name
mkdir -p "$IMG_DIR/$base_name"
# Move the image file into the folder
mv "$img_file" "$IMG_DIR/$base_name/"
echo "Moved $img_file to $IMG_DIR/$base_name/"
fi
done
echo "Done!"