ExifTool Forum

ExifTool => The "exiftool" Application => Topic started by: karldonteljames on May 11, 2022, 04:59:20 AM

Title: Renaming & Moving Files With EXIF Information (Import and Sort PhotoDump Folder)
Post by: karldonteljames on May 11, 2022, 04:59:20 AM
Good morning, Could someone help me rename files using aditional information please. at teh moment I have a script which processes files i save to a folder every ten minutes (in reality i might only add them once or twice a week, but i want them to show on my media machine as soon as possible for viewing.

at the moment the script is really simple, and is as follows:

find /mnt/user/MediaPictures/Import -type f -iname '*.jpg' -exec exiftool '-FileName<CreateDate' -d /mnt/user/MediaPictures/Export/%y%m%d/%%f.%%e \{\} \;
find /mnt/user/MediaPictures/Import -type f -iname '*.nef' -exec exiftool '-FileName<CreateDate' -d /mnt/user/MediaPictures/Export/%y%m%d'/RAW/'%%f.%%e \{\} \;


However ideally i'd like the files renamed too with
Artist - Camera Model - Shutter Count.extension
If there is anyway of adding the shutter speed and aperture to the filename that would be great,

e.g.

/220511/Karl - Nikon D700 - 44750 (1-400, f4).jpg
/220511/Karl - Nikon D700 - 44750 (1-400, f4).nef


I understand the resulting output of these contains '/' which is is disallowed for name names but this isnt essential. Thank you.
Title: Re: Renaming Files with aditional Information
Post by: karldonteljames on May 11, 2022, 07:04:17 AM

find /mnt/user/MediaPictures/Import -type f -iname '*.jpg' -exec exiftool '-FileName<CreateDate' -d /mnt/user/MediaPictures/Export/%y%m%d/%%f.%%e '-FileName<${shuttercount;} - ${model;} - ${artist;}.$fileTypeExtension' \{\} \;;

The above command renames the files but doesnt move them to the new location, the below commands moves them to the new location, but keeps the file names.

find /mnt/user/MediaPictures/Import -type f -iname '*.jpg' -exec exiftool '-FileName<${shuttercount;} - ${model;} - ${artist;}.$fileTypeExtension' '-FileName<CreateDate' -d /mnt/user/MediaPictures/Export/%y%m%d/%%f.%%e \{\} \;

Any advice on where I'm going wrong please?
Title: Re: Renaming Files with aditional Information
Post by: StarGeek on May 11, 2022, 09:54:41 AM
The first thing to do is remove the find.  This is Common Mistake #3 (https://exiftool.org/mistakes.html#M3).  Exiftool's biggest performance hit is the start up time and you don't want to run it separately on each file.  Just pass the directory and exiftool will process all files it can.  You can limit the scope with the -ext (-extension) option (https://exiftool.org/exiftool_pod.html#ext-EXT---ext-EXT--extension), in your case adding -ext jpg -ext nef

What you want to do in this case is remove everything that is not a date code from the -d (-dateFormat) option (https://exiftool.org/exiftool_pod.html#d-FMT--dateFormat) FMT string.  So
-d /mnt/user/MediaPictures/Export/%y%m%d/%%f.%%e
becomes
-d %y%m%d
All that other stuff now goes into the part that is copied to the Filename

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

See Renaming Examples (https://exiftool.org/exiftool_pod.html#RENAMING-EXAMPLES) and Writing "FileName" and "Directory" tags (https://exiftool.org/filename.html).
Title: Re: Renaming Files with aditional Information
Post by: karldonteljames on May 11, 2022, 10:13:17 AM
thank you i'll give that a try in a few minutes.

I'll run the exiftool over two command lines to process the nef and jpg files independantly as i want the nef files to go into a "raw" subfolder under the date. I assume that this could accomplished with:

#!/usr/bin/env bash

#Find jpeg Files and Autorotate
find /mnt/user/MediaPictures/Import -type f -iname "*.jpg" -exec jhead -autorot \{\} \;

#Read jpeg files, rename and move to date subfolder in export.
exiftool -ext jpg -d '%y%m%d' '-FileName</mnt/user/MediaPictures/Export/$CreateDate/${shuttercount;} - ${model;} - ${artist;}.%e' /mnt/user/MediaPictures/Import

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

#Find A Way To Autorotate NEF Files Via This Script

Title: Re: Renaming & Moving Files With EXIF Information (Import and Sort PhotoDump Folder)
Post by: StarGeek on May 11, 2022, 10:31:21 AM
That looks about right.

I don't believe NEFs, or any RAW filetype, can be actually rotated.  You would change the Orientation tag and any software should use that to load the file in the correct orientation.
Title: Re: Renaming & Moving Files With EXIF Information (Import and Sort PhotoDump Folder)
Post by: karldonteljames on May 11, 2022, 11:23:35 AM
Great thank you.

Sorry one more quick question, would the below command recursively work through the 2022 folder keeping all of the JPEGS in their current location, but moving all NEF files into a subfolder?


exiftool -ext jpg -r -d '%y%m%d' '-FileName<${shuttercount;} - ${model;}.%e' /mnt/user/MediaPictures/2022
exiftool -ext nef -r -d '%y%m%d' '-FileName</RAW/${shuttercount;} - ${model;}.%e' /mnt/user/MediaPictures/2022
Title: Re: Renaming & Moving Files With EXIF Information (Import and Sort PhotoDump Folder)
Post by: StarGeek on May 11, 2022, 01:50:30 PM
It would as long as the current directory was where you wanted to create the RAW directory.  It would be better to add the %d variable to make sure it was below the directory processed

For example
exiftool -ext nef -r -d '%y%m%d' '-FileName<%dRAW/${shuttercount;} - ${model;}.%e' /mnt/user/MediaPictures/2022
would create
/mnt/user/MediaPictures/2022/RAW/
even if the current directory was /mnt/user/MediaPictures/Import.
Title: Re: Renaming & Moving Files With EXIF Information (Import and Sort PhotoDump Folder)
Post by: karldonteljames on May 11, 2022, 05:13:07 PM
My plan was to run it against my entire 2022 folder which has subfolders in
e.g.

2022
-> Events
---> Graduation Day
-> Snaps
---> 220102 - Random Snaps
---> 220124 - Random Snaps

At the moment there are a mixture of raw and jpg files in those lower level folders.
I would like to run it against the entire folder structure and automagically move the nef files into a "RAW" subfolder in the folder they are currently in, so it would look like this.

2022
-> Events
---> Graduation Day
------> RAW
-> Snaps
---> 220102 - Random Snaps
------> RAW
---> 220124 - Random Snaps
------> RAW
Title: Re: Renaming & Moving Files With EXIF Information (Import and Sort PhotoDump Folder)
Post by: StarGeek on May 11, 2022, 08:08:50 PM
Try using TestName instead of Filename to see if the results would be what you want.
Title: Re: Renaming & Moving Files With EXIF Information (Import and Sort PhotoDump Folder)
Post by: karldonteljames on May 12, 2022, 04:02:32 AM
Perfect. Does exatcly what I need.

In one of the previous posts you said the orientation tag can be set on .NEF files, can this be set automatically? would there be a way of pulling the tag info from the associated jpg (in the folder above) and applying it only to portrait raw files using the folder structure above?
Title: Re: Renaming & Moving Files With EXIF Information (Import and Sort PhotoDump Folder)
Post by: StarGeek on May 12, 2022, 11:18:53 AM
Are your NEFs not showing the correct orientation?  Because unless you have your camera set not to include the correct orientation, they should already be correct.  It would be very unusual to be otherwise.  I would first check by running
exiftool -Orientation file.nef

But the basic command would be this, as long as they are in the same directory
exiftool -ext nef -TagsFromFile %d%f.jpg -Orientation /path/to/files/
Title: Re: Renaming & Moving Files With EXIF Information (Import and Sort PhotoDump Folder)
Post by: karldonteljames on May 12, 2022, 11:30:44 AM
Thank you. After looking again using my windows machine It doesn't seem to be a problem with the files. They are in the correct orientation, however, Emby is showing all of my images in landscape mode.