Estou tentando acrescentar DateTimeOriginal da foto aos nomes dos arquivos, mas o script não consegue renomear?
linuxmint@linuxmint:~/Documents$ ./rename_prepend_date.sh /media/linuxmint/USB\ STICK/Old\ drive/My\ pictures/IMG_0569.JPG
mv: cannot move '/media/linuxmint/USB STICK/Old drive/My pictures/IMG_0569.JPG' to '20110424_/media/linuxmint/USB STICK/Old drive/My pictures/IMG_0569.JPG': No such file or directory
Renamed '/media/linuxmint/USB STICK/Old drive/My pictures/IMG_0569.JPG' to '20110424_/media/linuxmint/USB STICK/Old drive/My pictures/IMG_0569.JPG'
Aqui está meu script bash:
#!/bin/bash
# Check if exiftool is installed
if ! command -v exiftool &> /dev/null; then
echo "exiftool is not installed. Please install it first."
exit 1
fi
# Check if a file is provided as an argument
if [ $# -eq 0 ]; then
echo "Usage: $0 <filename>"
exit 1
fi
# Loop through each provided file
for file in "$@"; do
# Get the date from the metadata (DateTimeOriginal)
date=$(exiftool -d "%Y%m%d" -DateTimeOriginal "$file" | awk -F': ' '{print $2}')
# Check if the date was successfully extracted
if [ -z "$date" ]; then
echo "Could not find a date for file $file. Skipping..."
continue
fi
# Extract the file extension and base name
extension="${file##*.}"
base="${file%.*}"
# Create the new filename by prepending the date
new_file="${date}_${base}.${extension}"
# Rename the file
mv "$file" "$new_file"
echo "Renamed '$file' to '$new_file'"
done