Author Topic: How to specify directory level  (Read 699 times)

WPNL

  • Newbie
  • *
  • Posts: 3
How to specify directory level
« on: October 22, 2018, 06:14:29 PM »
Hi guys, can you help me out with this?

I would like to add the parent's folder parent name into a tag

Disk
>Photos 2018-10-23
>>RAW
>>JPG

From inside "RAW" I would like to add "Photos 2018-10-23" into title for instance.
How can I get this data?

This is the code I'm using (trying to..) now:
D:\Installers\EXIF\exiftool.exe -r -m -overwrite_original "-ImageDescription<Photos of ${Directory;s/^\.$/use Cwd; cwd();/e;s/.*\///;} by me" -api "Filter=$_=uc" "N:\NEW PHOTOS\2018-10-23" -ext ARW

Thanks a lot in advance!

StarGeek

  • Global Moderator
  • ExifTool Freak
  • *****
  • Posts: 2748
Re: How to specify directory level
« Reply #1 on: October 22, 2018, 07:02:26 PM »
Try this as a baseline
exiftool "-ImageDescription<Photos of ${Directory;$_=(split '\/',$_)[-2]} by me"
to make sure it's the directory you want, then add the rest of your command.

Split with split the directory into an array on the slash.  Then the number in the brackets indicates the element of the array, in this case, second from the last.

So N:\NEW PHOTOS\2018-10-23\RAW will get split into
N:
NEW PHOTOS
2018-10-23
RAW
(exiftool uses slashes / instead of backslashes \ for directory paths, even on Windows) and would return second from the last, in this case 2018-10-23

Troubleshooting hints:
* When posting, include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).
* Double all percent signs (%) in a Windows batch file.
* If your GPS coords are negative, make sure and set the GpsLatitudeRef and GpsLongitudeRef tags correctly.

WPNL

  • Newbie
  • *
  • Posts: 3
Re: How to specify directory level
« Reply #2 on: October 23, 2018, 04:50:50 AM »
Thanks al lot for getting me started!

Unfortunatly the result is not what we expected, I've used this command:
C:/EXIF/exiftool.exe -m -overwrite_original "-ImageDescription<Photos of ${Directory;$_=(split '\/',$_)[-2]} by me" RAW/ -ext nef

The directory is: C:\Users\WP\Desktop\TEST\2018-10-23\RAW

After modifying the command to:
C:/EXIF/exiftool.exe -m -overwrite_original "-ImageDescription<Photos of ${Directory;$_=(split '\',$_)[-2]} by me" RAW/ -ext nef

Now the description is written with the right foldername but I get a warning:
Warning: Can't find string terminator "'" anywhere before EOF for 'Directory' - RAW/0002.nef

Of course I can ignore these but it doesn't feel right :-)

Phil Harvey

  • ExifTool Author
  • Administrator
  • ExifTool Freak
  • *****
  • Posts: 15115
    • ExifTool Home Page
Re: How to specify directory level
« Reply #3 on: October 23, 2018, 07:23:09 AM »
Odd.  StarGeek's command looks right to me, but maybe the quotes or backslash are the problem.  Try this:

C:/EXIF/exiftool.exe -m -overwrite_original "-ImageDescription<Photos of ${Directory;$_=(split m(/),$_)[-2]} by me" RAW/ -ext nef

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

StarGeek

  • Global Moderator
  • ExifTool Freak
  • *****
  • Posts: 2748
Re: How to specify directory level
« Reply #4 on: October 23, 2018, 04:02:00 PM »
Unfortunatly the result is not what we expected, I've used this command:
C:/EXIF/exiftool.exe -m -overwrite_original "-ImageDescription<Photos of ${Directory;$_=(split '\/',$_)[-2]} by me" RAW/ -ext nef

The directory is: C:\Users\WP\Desktop\TEST\2018-10-23\RAW

The problem is that you appear to be starting in C:\Users\WP\Desktop\TEST\2018-10-23 and processing the RAW directory below it.  In that case, the Directory tag by itself is going to return ./RAW and it won't be split the way you want it.  You can either use the full path in the command with the Directory tag as you did in your first example, or you can use the FilePath tag, which will always return the complete path and will get properly split.

Quote
After modifying the command to:
C:/EXIF/exiftool.exe -m -overwrite_original "-ImageDescription<Photos of ${Directory;$_=(split '\',$_)[-2]} by me" RAW/ -ext nef

Now the description is written with the right foldername but I get a warning:
Warning: Can't find string terminator "'" anywhere before EOF for 'Directory' - RAW/0002.nef

By removing the slash /, you're now escaping the single quote which is why there's a problem with the string termination.  Internally, exiftool will treat all directory paths as having a slash / directory separator, even on Windows.  So you need to escape the slash in the split command with a backslash.

I would suggest not using the second command going forward, as you may introduce errors down the line.  Switch Directory to FilePath should provide the correct results.
C:/EXIF/exiftool.exe -m -overwrite_original "-ImageDescription<Photos of ${FilePath;$_=(split m(/),$_)[-2]} by me" RAW/ -ext nef
Troubleshooting hints:
* When posting, include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).
* Double all percent signs (%) in a Windows batch file.
* If your GPS coords are negative, make sure and set the GpsLatitudeRef and GpsLongitudeRef tags correctly.

WPNL

  • Newbie
  • *
  • Posts: 3
Re: How to specify directory level
« Reply #5 on: October 23, 2018, 05:09:39 PM »
Thanks!  ;D I got the result I wanted and added some more fields:

C:/EXIF/exiftool.exe -m -overwrite_original -all= "-Title<${FilePath;$_=(split m(/),$_)[-3]}" "-ImageDescription<PHOTOS OF ${FilePath;$_=(split m(/),$_)[-3]} BY ME" "-Writer-Editor=ME" "-SubjectReference<${filename;s/\.[^.]*$//}" -rights="ME, ALL RIGHTS RESERVED" "-by-line=ME" "-credit=ME" "-CopyrightNotice=ALL RIGHTS RESERVED BY ME" "-source=ME.COM" -api "Filter=$_=uc" RAW/ -ext *