Hello,
I need to set Iptc:Caption-Abstract to some text that contains part of the filename.
Assuming the file is called "some file 'a' left.jpg", let's say I need to set Iptc:Caption-Abstract to "the left image of 'a'".
How could I achieve this?
Thank you.
Something like this should do what you want:
exiftool "-iptc:caption-abstract<the left image of ${filename;s/ left.*//}" FILE
where FILE is one or more file and/or directory names. The substitution expression (s///) deletes everything from " left" onwards in the file name.
The quoting above should work in Windows. Use single quotes instead if you are on Mac or Linux.
- Phil
Thank you for the fast reply. Assuming I need to scramble a little more the name, is there a way to specify something like "%15f", i.e to take 15 characters from the beginning, 3 from the middle, the last 5 ones, what should I do?
Where could I find the specs for expressions like the one you've proposed?
Are there any regular expressions available?
Thanks.
Beware: Regular expressions aren't for the faint of heart. This is considered an advanced feature of ExifTool.
Google for "Perl regular expression" for documentation on this. (Or even just "regular expression", since other languages use the same syntax.)
To do take 15 characters from the start and 5 from the end you could do this:
${filename;s/^(.{15}).*(.{5})\..*?$/some $1 text $2/}
where $1 and $2 would be the first 15 characters and the last 5. To take ones from the middle I would need to have some way to tell which 3 characters. The bit after (.{5}) in the expression just matches the file extension. Note that this expression contains a backslash, which can be tricky to escape in some shells.
- Phil
Thanks,
Regular expressions are not a problem to me, I have used them in TextPad, Notepad++, Visual C, C# and many more. But Perl is totally alien to me.
I think that's the issue. Now, I have a basic sample to start with.
Thank you.
Hello,
I have the following situation:
The text: blah blah lower blah blah g (optional here) left-01.jpg
The regex: /blah blah (lower|upper) blah blah (.{1}) (?:(.*))(left|right).*/
Here: http://www.solmetra.com/scripts/regex/index.php I can test and it shows:
Array
(
- => blah blah lower blah blah g (optional here) left-01.jpg
[1] => lower
[2] => g
[3] => optional here
[4] => left
)
It seems to match as I expect, but exiftool seems not.
What's wrong?
Thanks.
This isn't what you expected?:
> exiftool a.jpg -comment='blah blah lower blah blah g (optional here) left-01.jpg'
1 image files updated
> exiftool a.jpg -p '${comment;s/blah blah (lower|upper) blah blah (.{1}) (?:(.*))(left|right).*/$1|$2|$3|$4/}'
lower|g|(optional here) |left
- Phil
Yes, and I've just found the issue, it was a double quote missing that made the whole command a mess.
Thanks, I have to learn more now. :)
Hello!
I have a similar problem as mentioned in this topic, maybe someone can help me:
I got about 500 photos of my childhood scanned by my parents. All the description is in the file names. They all have a three digit number followed by two times space, then the description, e.g. "025 Minimundus Klagenfurt.jpg". What do I have to do to get Minimundus Klagenfurt to the caption?
Thank you very much and best regards from Germany,
Müsli
Try
exiftool "-Caption-Abstract<${filename;s/^\d{3} //}" FileOrDir
Try it out on a test file first to make sure it works like you want.
Hello StarGeek,
thank you very much for your reply.
Unfortunately the result was "025 Minimundus Klagenfurt.jpg;s/^\d{3} //}"
Did I make a mistake?
Thanks again an best wishes,
Müsli
If you're on a Mac, change the double quotes to single quotes ;)
Thanks, but my system is Windows :(
Somehow you missed the opening brace. The command works correctly here.
Notice I was able to replicate your output in the second command where I didn't have the opening brace.
c:\>exiftool "-Caption-Abstract<${filename;s/^\d{3} //}" "X:\!temp\025 Minimundus Klagenfurt.jpg"
1 image files updated
c:\>exiftool -caption-abstract "X:\!temp\025 Minimundus Klagenfurt.jpg"
Caption-Abstract : Minimundus Klagenfurt.jpg
c:\>exiftool "-Caption-Abstract<$filename;s/^\d{3} //}" "X:\!temp\025 Minimundus Klagenfurt.jpg"
1 image files updated
c:\>exiftool -caption-abstract "X:\!temp\025 Minimundus Klagenfurt.jpg"
Caption-Abstract : 025 Minimundus Klagenfurt.jpg;s/^\d{3} //}
Thank you StarGeek for your patience!
I did not forget the brace, I used copy and paste as well from your original post as from the new one. Your version with the missing brace produces the same output you had in this case and I have in both cases :(
I tried it with two opening braces but that screwed up things even more ;) I also tried to type the command by myself and not use copy and paste, same result.
Did you also use the windows command line?
Thanks, Müsli
What version of exiftool are you using (exiftool -ver)? I can't remember the exact version the advanced formatting was added but it has to be at least in the 9s.
I'm using a variant cmd line (PowerCmd, which I don't recommend for anyone using Win 8 or higher), but the command works fine in a regular CMD. Powershell tries to interpret the quoted part as a variable and throws back an error before it even runs :(
I think you got the point. Exiftool came installed with Geosetter (maybe you know that) and within Geosetter ist says version 10.10. But your command gets me 8.47. Maybe the installation path changed and I use the old one. I will check this out tomorrow and post the result.
All the best, Müsli
Geosetter places a copy of exiftool in it's appdata folder (for example, under windows 8.1, it's C:\Users\<USERNAME>\AppData\Roaming\GeoSetter\tools\exiftool.exe or just %appdata%\GeoSetter\tools) (Your post got me to finally add %appdata%\GeoSetter\tools to my PATH env var so now I'll always use the version that Geosetter has installed).
You can figure out where the exiftool you're using by the windows command where:
where exiftool
The old version which I used was in C:\Program Files (x86)\GeoSetter\tools, with the new one in %appdata% everything works fine :)
Thank you very much for your help and patience!
Best wishes, Müsli
P.S.: Just in case someone is interested, as written in Geosetter help I put
# The %Image::ExifTool::UserDefined hash defines new tags to be added
# to existing tables.
%Image::ExifTool::UserDefined = (
# Composite tags are added to the Composite table:
'Image::ExifTool::Composite' => {
# Composite tags are unique: The Require/Desire elements list
# tags that must/may exist, and the keys of these hashes are used
# as indices in the @val array of the ValueConv expression to
# derive the composite tag value. (See the Composite table in
# Image::ExifTool::Exif for more examples.)
BaseName => {
Require => {
0 => 'FileName',
},
# remove the extension from FileName
ValueConv => 'my $name=$val[0]; $name=~s/\..*?$//; $name',
},
# the following examples demonstrate simplifications which may be
# used if only one tag is Require'd or Desire'd:
# 1) the Require/Desire lookup may be replaced with a simple tag name
# 2) "$val" may be used to represent "$val[0]" in the expression
Extension => {
Require => 'FileName',
ValueConv => '$val=~/\.([^.]*)$/; $1',
},
},
);
into the .exiftool_config and replaced filename with BaseName in StarGeek's command line to get rid of the .jpg in the caption. Probably there is a better way to do so as I am not familiar with the ExifTool commands but it works ;)
Quote from: muesli on February 03, 2016, 09:36:22 AM
into the .exiftool_config and replaced filename with BaseName in StarGeek's command line to get rid of the .jpg in the caption. Probably there is a better way to do so as I am not familiar with the ExifTool commands but it works ;)
Using BaseName is probably the best way. It's easier to work with than the other way of using the advanced formatting and mistakes are less likely to happen.