ExifTool Forum

ExifTool => The "exiftool" Application => Topic started by: frereroy on October 25, 2012, 09:50:22 AM

Title: Help in adding path information as keywords
Post by: frereroy on October 25, 2012, 09:50:22 AM
Hello,

I would like to add the names of all the directories in the path leading to my jpgs as IPTC core keywords (separated by a "',")

I ideally I would like to drop a directory onto Exiftool and it would add recursively all the directory names that it finds in leading to the files as keywords.

Thanks for any help.

Title: Re: Help in adding path information as keywords
Post by: Phil Harvey on October 25, 2012, 10:45:40 AM
This config file will allow you to do what you want

Code: [Select]
%Image::ExifTool::UserDefined = (
    'Image::ExifTool::Composite' => {
        DirTree => {
            Require => 'Directory',
            ValueConv => q{
                # split directory into components
                my @parts = split '/', $val;
                # remove empty first component (if "/" was the first character)
                shift @parts if @parts and not $parts[0];
                return \@parts;
            },
        },
    },
);
1;  #end

with this command

exiftool "-keywords<dirtree" DIR

See the sample config file (http://owl.phy.queensu.ca/~phil/exiftool/config.html) for help activating this config file.

- Phil
Title: Re: Help in adding path information as keywords
Post by: frereroy on October 30, 2012, 01:32:32 PM
Thanks. I have got it working but only when I specify a directory name by replacing "DIR".

 It doesn't seem to recursively do the work on all the subdirectories contained under it.

Thanks for any help that you can supply.

Best wishes.
Title: Re: Help in adding path information as keywords
Post by: Phil Harvey on October 30, 2012, 01:34:04 PM
Add the -r option to recurse into sub-directories.

- Phil
Title: Re: Help in adding path information as keywords
Post by: frereroy on October 30, 2012, 01:41:04 PM
That worked. Many thanks.
Title: Re: Help in adding path information as keywords
Post by: waorak on March 05, 2015, 06:09:49 PM
If my path to my image files is Z:\images\holiday\Europe\France\ would adding the following lines to the script use only Europe and France as keywords:

Shift @parts if @parts and not $parts[1];
Shift @parts if @parts and not $parts[2];
Shift @parts if @parts and not $parts[3];

I would think that $parts[1] = "Z:", $parts[2] ="images", $parts[3] = "holiday" and shift would move past those?

Thank you
Russell
Title: Re: Help in adding path information as keywords
Post by: Phil Harvey on March 05, 2015, 07:32:57 PM
Hi Russel,

Close.  But try this:

Code: [Select]
shift @parts if @parts;
shift @parts if @parts;
shift @parts if @parts;

The "shift" is case sensitive, and you don't want to check to see if the parts are empty before you shift them out of the array (because they won't be).

Alternatively, you can add this line before splitting $val into parts:

Code: [Select]
$val =~ s(.*holiday[\\/])();
which will remove everything up to and including "holiday\" from the path before splitting the rest into parts.

- Phil
Title: Re: Help in adding path information as keywords
Post by: waorak on March 05, 2015, 08:13:37 PM
Wow, that was quick. Thank you for your help.

Thank you
Russell
Title: Re: Help in adding path information as keywords
Post by: pacman on March 06, 2015, 07:32:44 AM
I'm trying this on a Mac but am only getting "No writable tags set from PATH" error messages.
I've changed the slash to a backslash in this part of the script:

my @parts = split '\', $val;

I've also tried a bunch of other things, but I keep getting the same error message for my files.
I want to add the name of the folder as keywords, so a slight difference from the OP who wants the path as I understand it. And keywords should be added to any existing keywords in the image, not overwrite them.
Title: Re: Help in adding path information as keywords
Post by: Phil Harvey on March 07, 2015, 03:39:28 PM
You can specify a path in Windows with forward slashes when using ExifTool if you want.

To know what is going wrong, I need to see the exact value of the Directory tag when for some of the files in the command you are running.  i.e.)

exiftool -directory DIR

where DIR is the name of the directory you are specifying.

- Phil