Author Topic: How about recursively processing *selected* + subordinate folders ?  (Read 327 times)

chuft-captain

  • Jr. Member
  • **
  • Posts: 25
What I'm asking is almost the opposite of the question posed here: https://exiftool.org/forum/index.php?topic=7467.0

What if, instead of *ignoring* a selected folder, we want to parse all folders in the hierachy, but only process those images contained in (or in sub-directories below) a folder matching a specific name or pattern, and ignore all others?

eg. In this case we want to only process files contained in or below a sub-directory with the exact name "EDITS"
Quote
Top-level-DIR
     -Canon
         -ORIG
             -hires
         -EDITS <—— process files
             -hires <—— process files
             -lores <—— process files
     -Nikon
          -D300
             -ORIG
                 -hires
                 -lores
             -EDITS <—— process
                 -hires <—— process
                 -lores <—— process
          -D7200
             -ORIG
             -EDITS <—— process
                 -hires <—— process
                 -lores <—— process

... alternatively, instead of targeting an exact folder name like "EDITS", we might instead target files contained in (or below) any folders matching a particular naming style (such as a date pattern YYYY-MM-DD)...
eg.
Quote
Top-level-DIR
     -Canon
         -ORIG
             -hires
         -2010-10-04 <—— process files
             -hires <—— process files
             -lores <—— process files
     -Nikon
          -D300
             -ORIG
                 -hires
                 -lores
             -2012-03-12 <—— process
                 -hires <—— process
                 -lores <—— process
          -D7200
             -ORIG
             -2015-11-21 <—— process
                 -hires <—— process
                 -lores <—— process

... or perhaps only those beginning with the pattern "2015-"


StarGeek

  • Global Moderator
  • ExifTool Freak
  • *****
  • Posts: 3785
Re: How about recursively processing *selected* + subordinate folders ?
« Reply #1 on: January 25, 2020, 10:40:35 AM »
You could use the -if option and the Directory tag to limit the processed files. 

This does case insensitive processing of files in directories that contain "edits".  But take note that this would also process directories such as "credits".
exiftool -if "$Directory=~/edits/i" <more options and directory>

To process date format directories
exiftool -if "$Directory=~/\d{4}-\d\d-\d\d/i" <more options and directory>

Additionally, if the current directory was "EDITS", then these commands would fail if you didn't provide the full path.  If that was the case you would want to use FilePath instead of Directory.

Also, these commands wouldn't be the quickest because they's still be going through all the files, even those in other directories.

An alternative that may be a bit faster would be to use another program to get a list of all the directories that match the pattern, redirect that output into a temp file, and then use the -@ (Argfile) option to read that list.  You don't mention the OS, but under Mac/Linux, I believe you can use "find" for this.  And for Windows, I found this SuperUser answer.
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.

chuft-captain

  • Jr. Member
  • **
  • Posts: 25
Re: How about recursively processing *selected* + subordinate folders ?
« Reply #2 on: January 25, 2020, 11:08:06 AM »
Wow! Thanks for the really fast reply StarGeek ...

That's given me a good starting point ... I suspect I will need to throw in a "-r" as well (else parsing will stop at the top-level directory)?

Sorry, I should have mentioned that OS is Win7.  :-[

Thanks so much!

Phil Harvey

  • ExifTool Author
  • Administrator
  • ExifTool Freak
  • *****
  • Posts: 16687
    • ExifTool Home Page
Re: How about recursively processing *selected* + subordinate folders ?
« Reply #3 on: January 25, 2020, 09:25:23 PM »
Also, these commands wouldn't be the quickest because they's still be going through all the files, even those in other directories.

In this case you can use -if4 instead of -if to speed up ExifTool significantly.

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

chuft-captain

  • Jr. Member
  • **
  • Posts: 25
Re: How about recursively processing *selected* + subordinate folders ?
« Reply #4 on: January 25, 2020, 11:14:16 PM »
FYI,

The motivation behind my original question is that on occasion in the past I've had a tendency to use Windows Explorer's File Properties dialog to add caption information ... (not the best practice I guess) ... so I decided yesterday to do a bit of a spring-clean and get all those badly placed captions into a more useful and appropriate TAG.

I ended up with something along the lines of:

exiftool -r -if "$Directory=~/EDITS/i" "-iptc:Caption-Abstract<XPComment" "myPhotos" -preserve -overwrite_original

This took about 15 minutes (~10k image files updated, ~35k image files unchanged).
(I didn't think that was too bad)

In this case you can use -if4 instead of -if to speed up ExifTool significantly.
Just because I'm curious ... I may just repeat the process for comparison replacing -if with -if4 as per your suggestion Phil.

EDIT: Tried this, and it reported the following: Ignored superfluous tag name or invalid option: -if4 ... however, it still seems to have continued and processed the correct files. (Perhaps the -if4 switch is not supported in the version (10.68) that I'm running?)

The excellent thing about that -if "$Directory switch is that it allows me to process the files I need to, whilst avoiding making accidental metadata changes to the original files (which I generally try not to mess with).

Thanks both for your advice!

PS.
This does case insensitive processing of files in directories that contain "edits".  But take note that this would also process directories such as "credits".
I wonder if a bit of regex might allow exact matching and/or case sensitivity? ... (the latter probably a non-issue in Windows in any case)
« Last Edit: January 26, 2020, 03:42:00 AM by chuft-captain »

Phil Harvey

  • ExifTool Author
  • Administrator
  • ExifTool Freak
  • *****
  • Posts: 16687
    • ExifTool Home Page
Re: How about recursively processing *selected* + subordinate folders ?
« Reply #5 on: January 26, 2020, 06:39:30 AM »
EDIT: Tried this, and it reported the following: Ignored superfluous tag name or invalid option: -if4

This feature was added in ExifTool 11.18 (Nov 2018).  Try updating to a more recent version.  The current version is 11.84.

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

chuft-captain

  • Jr. Member
  • **
  • Posts: 25
Re: How about recursively processing *selected* + subordinate folders ?
« Reply #6 on: January 26, 2020, 09:07:38 PM »
Cheers Phil,

Obviously I'm a little wary about upgrading to new versions.  ;D :P
(just because of the risk of breaking other things in scripts I've written based on the 10.68 version).
That said, I think you're pretty good at making sure backward-compatibilty is maintained, so I guess the risk is minimal, so the question is ... What sort of speed increase would you expect to see using -IF4 over -IF?

StarGeek

  • Global Moderator
  • ExifTool Freak
  • *****
  • Posts: 3785
Re: How about recursively processing *selected* + subordinate folders ?
« Reply #7 on: January 26, 2020, 10:44:04 PM »
I've only had one occasion where there was a change to exiftool that broke anything and that was when there was a slight change to the return codes.  I was testing for an exact match (RC ==1, I think) when I should have just checked to see if it was not zero.  That was two years ago.
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.

chuft-captain

  • Jr. Member
  • **
  • Posts: 25
Re: How about recursively processing *selected* + subordinate folders ?
« Reply #8 on: January 27, 2020, 06:11:26 AM »

I'm NOT REALLY that paranoid about upgrading ... I was just poking a bit of fun at myself for still being on a 2-3 year old version!  ;)
I tend not to upgrade most software until I have a compelling reason to do so ... and the older version was already doing everything I needed it to do. (In general I think I just value software stability).

I appreciate the feedback about your past experience.
EXIFTOOLS is very easy to install/upgrade in fact, and FYI I've now installed the latest version.
I don't expect I'll have any issues as I'm not really doing a lot of advanced scripting, I'm not using the API,  and as you've reported, there's unlikely to be any issues wrt. backward compatibility.

Thanks again.