Writing directory structure into XMP tag

Started by gtrotter, November 04, 2013, 04:50:11 PM

Previous topic - Next topic

gtrotter

Hi

I am new to Exiftool but have downloaded and started using the ExifToolGUI. We have a large number of images stored within a structured file system i.e. c:\Africa\East Africa\Kenya\Nairobi\Norfolk Hotel\Image1.jpg. I would like to run a process to extract or parse the directory structure and to write the parsed data back as embedded meta data within the image. For example xmp:country=Kenya, xmp:region=Africa etc. I realise that there is no tag xmp:region but I imagine that I can either create a user defined tag or I can find a similar tag within the existing tag structure. Can anyone give me some pointers as to how I might achieve this parsing process using Exiftool?

Thank you.

Phil Harvey

Let me warn you that this will require using some advanced features that may be confusing to an ExifTool newbie...

You can either create a set of user-defined composite tags based on Directory (see the sample config file for more information).  With this, an expression like this could be used to return the top-level directory name (let's assume this tag is called "Dir1" in the command-line below):

ValueConv => 'my @a=split m{/}, $val; $a[1]',

And $a[2] will return the next level, etc.

The command line would then look something like this:

exiftool "-xmp:region<Dir1" "-xmp:country<Dir2" ... -r BASE_DIR

where BASE_DIR is the root of your directory heirarchy.

Alternatively, you could do it using the advanced formatting feature.  The command is more complicated, but it doesn't require a custom configuration file.  For this, I would advise putting the arguments in a separate file since they are rather complex.  The argument file would then look something like this (let's call it "my.args"):

-xmp:region<${directory;my @a=split m{/};$_=$a[1]}
-xmp:country<${directory;my @a=split m{/};$_=$a[2]}
...


and a command would be:

exiftool -@ my.args -r BASE_DIR

- Phil

Disclaimer: I didn't have time to test any of this out, so I can't be sure there aren't any typos in my examples.  Read the application documenation for more details.
...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 ($).

gtrotter

Thank you. That's fantastic support. They key here is the split function, which is the pointer that I was looking for. I will have a play and try and get this working. I do have another question but will put it in a separate thread.

Thanks