ExifTool Forum

ExifTool => Newbies => Topic started by: markman8 on November 16, 2022, 05:09:25 AM

Title: ShutterActuations (ShutterCounts) on renaming files
Post by: markman8 on November 16, 2022, 05:09:25 AM
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?
Title: Re: ShutterActuations (ShutterCounts) on renaming files
Post by: Phil Harvey on November 16, 2022, 10:38:26 AM
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 (https://exiftool.org/filename.html#codes) 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
Title: Re: ShutterActuations (ShutterCounts) on renaming files
Post by: markman8 on November 16, 2022, 12:14:50 PM
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)
Title: Re: ShutterActuations (ShutterCounts) on renaming files
Post by: markman8 on November 16, 2022, 12:20:58 PM
Sorry forgot to change the "." in the exiftool commands with the $DIR variable in the script so keep that in mind
Title: Re: ShutterActuations (ShutterCounts) on renaming files
Post by: markman8 on November 16, 2022, 12:39:33 PM
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.
Title: Re: ShutterActuations (ShutterCounts) on renaming files
Post by: Phil Harvey on November 16, 2022, 01:27:51 PM
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