Hi there! New to exiftool and the impressive array of functionalities it offers. What I am trying to do is this:
Many of my folder names have a description for the photos they contain. There is, however, not a completely rigid format for the folder name. Three types exist:
(1) 2014\2014_07_21 - Birthday
(2) 2014\2014_08_01-15 - Holiday in Spain
(3) 2014\2014_09_15
Hence, some have just one date with a description, others a range of dates with a description, and some don't have a description at all.
What I would like to do is, recursively on my whole Photo folder (of which the above would be direct subfolders):
- get the start of the description from the folder name, if there is any (I would think by locating " - " with an index function?)
- put the description in a string
- write that string to the EXIF Description of all image files in the folder
I had found some posts closely related to this, but the extra difficulty of first getting the substring with the " - " delimiter proves a challenge...
Anyone care to be so kind to hep me out? Thanks!!
(PS: Pictures are stored on Synology NAS; I could run exiftool there, or go via my Windows PC.)
Try this:
exiftool -r "-imagedescription<${directory;s/.* - // ? $_ : undef}" DIR
Here I assume you meant EXIF:ImageDescription. There is no EXIF tag named "Description".
This command avoids writing a description if none existed in the directory name by checking the returned value of the substitution and setting the value to "undef" if no substitution was made.
- Phil
Many thanks, Phil! Doing some testing, but seems to work fine, apart from writing the folder name to the ImageDescription (indeed, the tag I intended) in case there is no description given in the folder name. So the 'undef' trick may not be working (but still investigating); I'm doing the tests in a Windows environment BTW.
Update: The ternary operator (? : ) is basically left untreated, it turns out, the processed (substituted) string is always returned and written. Hence, if there's no substitution to be made (no description), the folder name is written to the tag. Any idea how to solve this?
Right, I forgot to assign "undef" back to $_. The command should have been:
exiftool -r "-imagedescription<${directory;$_ = s/.* - // ? $_ : undef}" DIR
- Phil
Great - that does the trick! I do understand the gist of what's going on, but have too little knowledge of exactly how values are returned etc in Perl / regex to be able to come up with that. Many thanks!! (And congrats for the amazing work on exiftool!)
Hi there, and thanks for this great tool.
I'm dealing with the same task as slashedzero, but my folders are all like:
"2019-01-06 Trip to Mars"
So no " - ", just the date followed by space.
I'm trying to modifiy the code, but no luck.
Any help will be greatly apreciated.
Thanks!
Try this:
exiftool -r "-imagedescription<${directory;$_ = s/.*? // ? $_ : undef}" DIR
The ? causes .* to match the fewest number of characters possible (before the space). Without this, you would only get the last word in the directory name.
- Phil
Thanks for the quick reply.
It works!! Thank you.
Although the Parent folder for the subfolders can't have any spaces in it.
Ex:
"\Main folder\2019-01-06 Trip To Mars"
Results in:
"folder\2019-01-06 Trip To Mars"
Also in leaves the space in ImageDescription:
" Trip To Mars"
Thanks again!
Right. You could remove the parent folder first, then everything up to and including the space:
exiftool -r "-imagedescription<${directory;s(.*/)();$_ = s/.*? +// ? $_ : undef}" DIR
I didn't understand your comment about the extra space, so I added a "+" to avoid this problem if there were two spaces before the description.
- Phil
Is there a way to set the description equal to the full parent folder name?
On a Mac, I tried this:
exiftool -r '-imagedescription<${directory;s(.*/)();$_ = s/.*? +// ? $_ : undef}' IMG00001.jpg
and got back this:
Warning: [minor] Advanced formatting expression returned undef for 'directory' - IMG00001.jpg
Warning: No writable tags set from IMG00001.jpg
0 image files updated
1 image files unchanged
Adams-iMac:Pinetop 1960 Adam$
The reason nothing was updated is because you're in the same directory as the image. If you run
exiftool -directory IMG00001.jpg
you'll see that the results are
Directory : .
A single dot for the directory stands for the current directory and the as you can see, doesn't show the parent directory. You can either replace IMG00001.jpg with the full path to the file or directory, or use a more complicated expression that makes use of the FilePath variable.
Try this:
exiftool '-imagedescription<${FilePath;$_=(split '\/',$_)[-2]}' IMG00001.jpg
For more details on how this comand works, see this post (https://exiftool.org/forum/index.php/topic,9606.msg49791.html#msg49791).
My needs are much simpler. I have a set of folders where I want to write the whole name of the folder into the ImageDescription tag. I don't need to extract part of the folder name first. How would I write a command to do this?
1. "cd" to the folder containing all of the folders with the images.
2. exiftool "-description<directory" -r *
This will put the relative directory path into the Description. If you want an absolute path instead, do this:
1. exiftool "-description<directory" -r c:\path\to\root\folder
- Phil
Thanks for this. I'm struggling with this. I'm on macOS. I open Terminal and cd to the folder, which in my case is:
/Volumes/Main\ Storage/\ Lightroom\ Import/Africa\ puzzle
I have one file in this folder. I enter this command:
exiftool "-imagedescription<directory" -r *
I observe the result with this command:
exiftool -ImageDescription *
The ImageDescription is now a period, ., not the name of the folder. What have I done wrong? Thanks.
Read Phil's post carefully. Don't CD to the directory with files, as the directory will be the dot, which stands for the current directory.
I've had success now, with the folder name, and not the whole path, in the ImageDescription.
In Lightroom, this tag is labelled Caption. It's not Title, which was what I was expecting.
The directory that you "cd" into won't appear in the caption. Only directories below this will. If you want "Africa puzzle" in the caption, then cd to "/Volumes/Main Storage/ Lightroom Import/" to run the exiftool command.
You can see what ExifTool will write with this command:
exiftool -directory FILES
- Phil
Edit: Oops. I see StarGeek already responded -- I was only looking at page 1 of the responses
Thanks. I've got it working now, so the directory:
/Volumes/Main\ Storage/\ Lightroom\ Import/Africa\ puzzle
is processed to write Africa Puzzle into what is called the Caption field in Lightroom, and I'm doing it on multiple images in multiple folders, recursively. The part of the path that I want is what I am getting, so that's fine. I would prefer it to write into what Lightroom calls the Title field.
1. Write the title with Lightroom
2. Use exiftool -a -G1 -s to see where the title was written, then write it to the same location(s) with ExifTool.
- Phil
Edit: StarGeek has already figured this out for you. Read here (https://exiftool.org/forum/index.php?topic=6959.0).
That is data from ver 4.4 of LR, but it should still be the same as the current version of Bridge still writes there.