ExifTool Forum

ExifTool => Newbies => Topic started by: karldonteljames on November 13, 2023, 01:24:56 PM

Title: Handling an error on renaming jpgs.
Post by: karldonteljames on November 13, 2023, 01:24:56 PM
I currently use the following script with exif to import all of the images I dump in a folder. However one of my children have a crapphy camera that doesn't support shutter count, So I would like to replace the shutter count if there is an error with the time in hh:mm:ss format in the same place in the filename. The error that is thrown up is
Warning: [minor] Tag 'shuttercount' not defined - /mnt/user/MediaPictures/Import/IMG_0236.JPG
Warning: No writable tags set from /mnt/user/MediaPictures/Import/IMG_0236.JPG

My full script at the moment is:
#!/usr/bin/env bash

#Find jpeg Files and Autorotate
echo Rotating Portrait JPEG Files as Required.
find /mnt/user/MediaPictures/Import -type f -iname "*.jpg" -exec jhead -autorot \{\} \;
echo COMPLETE: Portrait JPEG Files Rotated as Required.

#Read jpeg files, rename and move to date subfolder in export.
echo Moving and Renaming JPEG Files to Export folder.
exiftool -ext jpg -r -d '%y%m%d' '-FileName</mnt/user/MediaPictures/Export/$CreateDate/${shuttercount;} - ${model;}.%e' /mnt/user/MediaPictures/Import
echo COMPLETE: Moved and Renamed JPEG Files Moved.

#Read nef (Nikon RAW) files, rename and move to raw subfolder within date subfolder in export.
echo Moving and Renaming RAW Files to Export folder.
exiftool -ext nef -r -d '%y%m%d' '-FileName</mnt/user/MediaPictures/Export/$CreateDate/RAW/${shuttercount;} - ${model;}.%e' /mnt/user/MediaPictures/Import
echo COMPLETE: Moved and Renamed RAW Files Moved.

#Read arw (Sony RAW) files, rename and move to raw subfolder within date subfolder in export.
echo Moving and Renaming RAW Files to Export folder.
exiftool -ext arw -r -d '%y%m%d' '-FileName</mnt/user/MediaPictures/Export/$CreateDate/RAW/${shuttercount;} - ${model;}.%e' /mnt/user/MediaPictures/Import
echo COMPLETE: Moved and Renamed RAW Files Moved.

#Change Ownership of new files so they can be moved via SMB
echo Changing Ownership of new files.
chown nobody:users -R '/mnt/user/MediaPictures/Export/'
chmod 777 -R '/mnt/user/MediaPictures/Export/'
echo COMPLETE: Ownership Changed For New Files.

Any advice on how I can change this to handle error would be really appreciated. The error will only be present on jpg files, as any camera that supports raw also supports shutter count.

Thank you.
Title: Re: Handling an error on renaming jpgs.
Post by: Phil Harvey on November 13, 2023, 01:36:54 PM
I wouldn't suggest using colons in a file name -- they are illegal on some filesystems -- but here you go.  You would change all the commands from something like this:

exiftool -ext jpg -r -d '%y%m%d' '-FileName</mnt/user/MediaPictures/Export/$CreateDate/${shuttercount;} - ${model;}.%e' /mnt/user/MediaPictures/Import

to this

exiftool -ext jpg -r -d '%y%m%d' '-FileName</mnt/user/MediaPictures/Export/$CreateDate/${createdate#;DateFmt("%H:%M:%S")} - ${model;}.%e' '-FileName</mnt/user/MediaPictures/Export/$CreateDate/${shuttercount;} - ${model;}.%e' /mnt/user/MediaPictures/Import

This will set the filename from ShutterCount if it exists, or CreateData otherwise.  You can add -q -q to the command to suppress the warnings that you will see when ShutterCount is missing, but this will also suppress the summary messages.

- Phil
Title: Re: Handling an error on renaming jpgs.
Post by: karldonteljames on November 13, 2023, 01:38:35 PM
I'm happy to lose the colons, it was more just to show how I would like files renamed if shuttercount wasn't an option. Would your suggestion use shuttercount by default, then if that failed use the time taken?

Sorry just re-read the part at the end of the response. I'll give that a try. Thank you.
Title: Re: Handling an error on renaming jpgs.
Post by: karldonteljames on November 13, 2023, 01:43:55 PM
I've run that on a couple of test pictures and they have been renamed to:

12QPPD~J.JPG
12901E~B.JPG

however they have the information in the images.
Datetaken: 24/06/2005
Camera Model: Concord 5340z


Ahh, I assume that is because of the colons!
Title: Re: Handling an error on renaming jpgs.
Post by: karldonteljames on November 13, 2023, 01:45:53 PM
it was! Removed the colons and it seems to have worked. Thank you so much for your help!
Title: Re: Handling an error on renaming jpgs.
Post by: Phil Harvey on November 13, 2023, 01:49:33 PM
Great!