Author Topic: Help in adding path information as keywords  (Read 4278 times)

frereroy

  • Full Member
  • ***
  • Posts: 31
Help in adding path information as keywords
« 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.


Phil Harvey

  • ExifTool Author
  • Administrator
  • ExifTool Freak
  • *****
  • Posts: 14733
    • ExifTool Home Page
Re: Help in adding path information as keywords
« Reply #1 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 for help activating this config file.

- 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 ($).

frereroy

  • Full Member
  • ***
  • Posts: 31
Re: Help in adding path information as keywords
« Reply #2 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.

Phil Harvey

  • ExifTool Author
  • Administrator
  • ExifTool Freak
  • *****
  • Posts: 14733
    • ExifTool Home Page
Re: Help in adding path information as keywords
« Reply #3 on: October 30, 2012, 01:34:04 PM »
Add the -r option to recurse into sub-directories.

- 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 ($).

frereroy

  • Full Member
  • ***
  • Posts: 31
Re: Help in adding path information as keywords
« Reply #4 on: October 30, 2012, 01:41:04 PM »
That worked. Many thanks.

waorak

  • Newbie
  • *
  • Posts: 2
Re: Help in adding path information as keywords
« Reply #5 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

Phil Harvey

  • ExifTool Author
  • Administrator
  • ExifTool Freak
  • *****
  • Posts: 14733
    • ExifTool Home Page
Re: Help in adding path information as keywords
« Reply #6 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
...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 ($).

waorak

  • Newbie
  • *
  • Posts: 2
Re: Help in adding path information as keywords
« Reply #7 on: March 05, 2015, 08:13:37 PM »
Wow, that was quick. Thank you for your help.

Thank you
Russell

pacman

  • Full Member
  • ***
  • Posts: 49
Re: Help in adding path information as keywords
« Reply #8 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.
« Last Edit: March 06, 2015, 09:39:36 AM by pacman »

Phil Harvey

  • ExifTool Author
  • Administrator
  • ExifTool Freak
  • *****
  • Posts: 14733
    • ExifTool Home Page
Re: Help in adding path information as keywords
« Reply #9 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
...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 ($).