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.
This config file will allow you to do what you want
%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 (https://exiftool.org/config.html) for help activating this config file.
- Phil
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.
Add the -r option to recurse into sub-directories.
- Phil
That worked. Many thanks.
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
Hi Russel,
Close. But try this:
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:
$val =~ s(.*holiday[\\/])();
which will remove everything up to and including "holiday\" from the path before splitting the rest into parts.
- Phil
Wow, that was quick. Thank you for your help.
Thank you
Russell
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.
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
Hopefully this will be seen since it's so old. I too am having the same problem pacman reported. I've tried several variations with no luck. I didn't see any additional traffic after your response so I'm not sure if this was solved. I'm sure it's something simple I'm missing, but it's driving me crazy.
Brians-MacBook-Pro:Temp 2 bcossiboom$ exiftool "-keywords+<DirTree" * -r
Warning: No writable tags set from Shooter/GM032119-0186.jpg
Warning: No writable tags set from Shooter/GM032119-0282.jpg
Warning: No writable tags set from Shooter/GM032119-0241.jpg
1 directories scanned
0 image files updated
3 image files unchanged
Brians-MacBook-Pro:Temp 2 bcossiboom$ exiftool -directory *
======== Shooter/GM032119-0186.jpg
Directory : Shooter
======== Shooter/GM032119-0282.jpg
Directory : Shooter
======== Shooter/GM032119-0241.jpg
Directory : Shooter
1 directories scanned
3 image files read
For your first command, did you copy the DirTree config to your .exiftool_config file. You have to do either that or create a separate config file and use the -Config option (https://exiftool.org/exiftool_pod.html#config-CFGFILE).
Copy the code in the second post (https://exiftool.org/forum/index.php?topic=4513.msg21444#msg21444). Open a text editor (not a word processor). Paste the code into and save it into the same directory as exiftool. Give it an obvious name such as DirTree.config Then run
exiftool -config DirTree.config "-keywords+<DirTree" -r /path/to/directory
Thank you for the speedy reply!
I'm still missing a critical step somewhere b/c ExifTool isn't seeing the DirTree.config file. It now exists everywhere (e.g. my home directory, the root directory with the ExifTool Unix Executable, /usr/local/bin/lib, /usr/local/bin/lib/Image, /usr/local/bin/lib/Image/ExifTool/) and I still can't get it to work. I read in other forum posts that I could specify the config file location, but that caused more problems/errors (not sure why).
I went back through the example.config instructions and I've followed them to the letter (and then did it again just to make sure). I've also reinstalled ExifTool and then repeated the steps above. I'm sure it's something simple that I'm missing, but it's eluding me.
There is a format error in your config file. Attach the config file you are using and we'll be able to help.
In your first screenshot the config file was found, but it contains errors.
- Phil
Attached as requested. Thank you!
Attached as requested. I wasn't able to upload the .DirTree.config file, so I've attached the file used to create it. Thank you!
Wow. There you go. The file is RTF format. The config file must be plain text. Try the attached version.
- Phil
That did the trick - THANK YOU!!!