ShutterActuations (ShutterCounts) on renaming files

Started by markman8, November 16, 2022, 05:09:25 AM

Previous topic - Next topic

markman8

Hello to all,

I am writing a script in bash shell linux to change the name of the imported pictures to include the shutter actuations among the model name of the camera and tha CreateDate.

Is there a way to do that in a single line or otherwise?

Phil Harvey

Yes.  Something like this:

exiftool "-testname<${createdate}_${model;}_${shuttercount}.%e" -d "%Y-%m-%d_%H%M%S" DIR

The semicolon after "model" uses the advanced formatting feature to delete invalid characters from the model name.

See the Date format codes section of the file-renaming page for more details about the date/time formatting string.

Once you are convinced the file names are what you want, change "testname" to "filename" to actually rename the files.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

markman8

Thank you very much!

In the mean time I wrote the script that included the $filenumber instead of ${shuttercount} as you mentioned.

Here it is altogether:
#!/bin/bash
FILE=""
DIR="$1"
if [ -d "$DIR" ]
then
    if [ "$(ls -A $DIR)" ]
    then
        exiftool '-Directory<DateTimeOriginal' -d %m%Y .
        exiftool '-filename<${model;}_${createdate#;DateFmt("%d-%b-%y_%H%M%S")}_$filenumber.%e' . -r
        # exiftool '-filename<${model;}_${createdate#;DateFmt("%d-%b-%y_%H%M%S")}_${shuttercount}.%e' . -r
    else
        echo "$DIR is Empty"
    fi
else
    echo "Directory $DIR not found."
fi

I included here the line you mentioned REMed replacing $filenumber with ${shuttercount} (have not tested it I thing it will work if unREMed)

markman8

Sorry forgot to change the "." in the exiftool commands with the $DIR variable in the script so keep that in mind

markman8

Sorry one more,  the script included here is the correct one.
#!/bin/bash
FILE=""
DIR="$1"
#DIR="."
if [ -d "$DIR" ]
then
        if [ "$(ls -A $DIR)" ]
        then
                cd $DIR
                exiftool '-Directory<DateTimeOriginal' -d %m%Y .
                #exiftool '-filename<${model;}_${createdate#;DateFmt("%d-%b-%y_%H%M%S")}_$filenumber.%e' . -r
                exiftool '-filename<${model;}_${createdate#;DateFmt("%d-%b-%y_%H%M%S")}_${shuttercount}.%e' . -r
        else
                echo "$DIR is Empty"
        fi
else
        echo "Directory $DIR not found."
fi

Processed two kind of pictures with the ${shuttercount} attribute one of those failed with the following message:
Warning: [minor] Tag 'shuttercount' not defined - ./082022/BC1X1105.CR2
Warning: No writable tags set from ./082022/BC1X1105.CR2

So it does not always work.  The $filenumber does the work just fine!  Note that if you leave out the $filenumber will not process all photos taken in the same second in time.

Phil Harvey

You can move and rename the file in one command:

exiftool '-filename<${datetimeoriginal}/${model;}_${createdate#;DateFmt("%d-%b-%y_%H%M%S")}_${shuttercount}.%e' -d %m%Y . -r

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).