Import IPTC data from filename

Started by pluto007, October 24, 2011, 04:29:54 AM

Previous topic - Next topic

pluto007

Hello,

i have a lot of files with named e.g. "number- country - region - something - number"
Is it possible to import this values in the IPTC field caption somhow?

Thanks a lot!
pluto

Phil Harvey

Yes.  If you don't want to include the file extension, use the sample config file included in the Perl distribution to give you the BaseName tag, then do this:

exiftool "-caption-abstract<basename" DIR

where DIR is the name of a directory containing your images.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

pluto007

Hello Phil,

thank you for your very fast answer, but I think I'm not able to understand ...?
What do you mean by "-caption-abstract<basename" - I can not find these options anywhere?

I would like to use the IPTC-Field caption to store the whole filename (if possible without ".jpg" and maybe there's a way to replace the "-" with something else in one way, too.)

Could you please help me a little bit more? I can't figure it out of the documentation?

Thank you a lot!
pluto

Phil Harvey

This is explained in the document of the -tagsFromFile option.  Also see the Tag Name documentation for a list of available tags.

The BaseName tag is a user-defined tag that is included in the sample config file that I mentioned.  The Caption-Abstract tag is one of the standard IPTC tags.

The argument "-caption-abstract<basename" copies the BaseName tag to Caption-Abstract.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

pluto007

Hello Phil,

Great it works!
Is there a way to replace some characters inside the IPTC caption, too?
I found only the option to rename the files themselves.

Thanks again for your great work.
pluto

Phil Harvey

Hi Pluto,

There are various examples of how to do this in other threads of this forum.  Here is one.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

pluto007

Hello Phil,

ah I see, I use the folowing code now in my config file:

MyDescription => {
          Require => 'Caption-Abstract',
          ValueConv => '$val =~ s{;}{<br>}g ? $val : undef',
          ValueConv => '$val =~ s/#[0-9]*//g ? $val : undef',
        },


and start it with the following command: exiftool  "-Caption-Abstract<myDescription"
The problem is that only the second replacement is done of course.

The question is how to get both replacements done in one way?
Is this possible?

The IPTC caption looks like the following at the beginning:
"text1 ; text2 ; text3#001"
and should look like
"text1 <br> text2 <br> text3" afterwards.

Of course it would be possible to define another part in the config file, but I think there's a better way...

Thanks a lot
pluto

Phil Harvey

Hi Pluto,

Try this:

        MyDescription => {
          Require => 'Caption-Abstract',
          ValueConv => '$val =~ s{;}{<br>}g; $val =~ s/#[0-9]*//g; $val',
        },


Here I don't bother to return 'undef' if no substitution is made.  The idea of this in the other thread was that the Composite tag wouldn't be defined if there was nothing to substitute, but maybe that isn't necessary here.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

pluto007

Hello Phil,

great - works as a charme!

A BIG Thank you for you!

pluto