Rename also other files with the same name

Added by Camilo Rada 27 days ago

Hi, I love exiv2 and often use it to rename my pictures. The problem I have is that I frequently take voice notes, a feature available in most cameras. The voice note is saved in a .WAV audio file with the same name than the image. As you can imagine, after renaming the images I lose track of what audio files correspond to what images. As I want to keep both files with the same name, my current workaround is to add the -v option and save it to a text file, like:

exiv2 -Fv mv *.JPG > JPG_renames.txt

Then I edit the text file (that contain the old and new names) with some search&replace and regular expressions to turn it into a script that renames the WAV files. As you can imagine, that's cumbersome and I wonder if I can get exiv2 to do the renaming of the WAV files automatically.

Thanks

Camilo


Replies (1)

RE: Rename also other files with the same name - Added by Robin Mills 27 days ago

The exiv2 command-line program doesn't have any option to say "when you rename a file, run this script". However I've written a script wav_buddy.sh to read your file "JPG_renames.txt".

#!/bin/bash

r=JPG_renames.txt
while read line; do
    action=$(echo $line | cut -d' ' -f 1)
    if [ "$action" == "File" ]; then
        jpg=$(echo $line | cut -d' ' -f 3)
        old_name=$(basename -s .JPG "$jpg").wav
    fi
    if [ "$action" == "Renaming" ]; then
        jpg=$(echo $line | cut -d' ' -f 4)
        new_name=$(basename -s .JPG "$jpg").wav
        echo mv "$old_name" "$new_name" 
    fi
done < $r

# That's all Folks!
##

Here's the script in action:

641 rmills@rmillsmbp:~/temp/photos $ ls -lt
-rwxr-xr-x   1 rmills  staff  6400556 25 Apr 09:07 DSC_8073.JPG
-rwxr-xr-x   1 rmills  staff  6174465 25 Apr 09:07 DSC_8072.JPG
-rwxr-xr-x   1 rmills  staff  6195629 25 Apr 09:07 DSC_8071.JPG
-rwxr-xr-x@  1 rmills  staff      386 25 Apr 09:02 wav_buddy.sh

642 rmills@rmillsmbp:~/temp/photos $ exiv2 -Fv mv *.JPG > JPG_renames.txt

643 rmills@rmillsmbp:~/temp/photos $ cat JPG_renames.txt 
File 1/3: DSC_8071.JPG
Renaming file to ./20180423_180523.JPG
File 2/3: DSC_8072.JPG
Renaming file to ./20180423_180535.JPG
File 3/3: DSC_8073.JPG
Renaming file to ./20180423_180552.JPG
644 rmills@rmillsmbp:~/temp/photos $ ls -lt
-rw-r--r--   1 rmills  staff      186 25 Apr 09:08 JPG_renames.txt
-rwxr-xr-x   1 rmills  staff  6400556 25 Apr 09:07 20180423_180552.JPG
-rwxr-xr-x   1 rmills  staff  6174465 25 Apr 09:07 20180423_180535.JPG
-rwxr-xr-x   1 rmills  staff  6195629 25 Apr 09:07 20180423_180523.JPG
-rwxr-xr-x@  1 rmills  staff      386 25 Apr 09:02 wav_buddy.sh

645 rmills@rmillsmbp:~/temp/photos $ ./wav_buddy.sh 
mv DSC_8071.wav 20180423_180523.wav
mv DSC_8072.wav 20180423_180535.wav
mv DSC_8073.wav 20180423_180552.wav
646 rmills@rmillsmbp:~/temp/photos $ 

The script wav_buddy.sh could execute the command exiv2 -Fv mv *.JPG > JPG_renames.txt for you.

So a simple script can rename both your .JPG and .WAV files. No file editing or other error-prone manual intervention needed.

I hope you find this useful. I won't support the script wav_buddy.sh which is provided to illustrate my approach to dealing with your scenario.

(1-1/1)

Redmine Appliance - Powered by TurnKey Linux