ExifTool Forum

ExifTool => The "exiftool" Application => Topic started by: Tom Cunningham on April 21, 2020, 11:59:09 PM

Title: Exiting directory on recursive conditional
Post by: Tom Cunningham on April 21, 2020, 11:59:09 PM
I have the following command:

exiftool -ext JPG -if '$xmptoolkit !~ /ExifTool/' -xmptoolkit -r .

which works fine, but what I would like it to do is, when the condition is met, simply print the directory name and move on to the next directory.  In other words, I don't need to see every file that meets the condition, just the directory where it resides.  Is there any way to do that from the command line?
Title: Re: Exiting directory on recursive conditional
Post by: Phil Harvey on April 22, 2020, 08:20:07 AM
Hi Tom,

Interesting idea.  I will add a feature to ExifTool 11.95 to allow you to do this:

exiftool -ext JPG -if '$xmptoolkit !~ /ExifTool/ and ExitDir()' -xmptoolkit -directory -r .

(Now I just have to figure out how to document this.)

- Phil

Edit: The function is called EndDir() in ExifTool 11.96 and later.
Title: Re: Exiting directory on recursive conditional
Post by: Phil Harvey on April 23, 2020, 09:28:16 AM
Hi Tom,

11.95 is now available.

- Phil
Title: Re: Exiting directory on recursive conditional
Post by: Phil Harvey on April 23, 2020, 12:54:43 PM
Update:  I didn't really like the names of the Exit() and ExitDir() functions that I added because they are too close to the system exit() call which exits the program (and could be a problem if someone called this by accident).  I had thought of maybe Done() and DoneDir(), but I didn't like those either.

But I just came up with End() and EndDir().  Any opinions?

- Phil
Title: Re: Exiting directory on recursive conditional
Post by: Tom Cunningham on April 23, 2020, 07:04:05 PM
Works great, Phil, thanks!  End() and EndDir() are fine with me; will that be in 11.96?
Title: Re: Exiting directory on recursive conditional
Post by: Phil Harvey on April 23, 2020, 09:04:52 PM
Yes.  Right now with 11.95 it is Exit() and ExitDir(), but with 11.96 it will be End() and EndDir().  If things go well I may be able to release 11.96 tomorrow.

- Phil
Title: Re: Exiting directory on recursive conditional
Post by: Phil Harvey on April 24, 2020, 12:09:48 PM
ExifTool 11.96 is now available.
Title: Re: Exiting directory on recursive conditional
Post by: georgejones314 on May 12, 2020, 10:59:58 AM
Sorry if this is a simpleton mistake.

I have the following line in a batch file:
c:\software\exiftool.exe -if '"not $track" %folder% ExitDir() and goto SKIP'

The idea is to ignore a folder if any file within a folder has an entry in the tag $track

Instead I get this message:

Error: File not found - ExitDir()
Error: File not found - and
Error: File not found - goto
Error: File not found - skip'

I don't want any output at all ... just skip to the end of the routine.

I'm using version 11.9.9

Thx
Title: Re: Exiting directory on recursive conditional
Post by: StarGeek on May 12, 2020, 12:08:14 PM
Your quoting is wrong and you seem to be including batch commands inside the exiftool processing.

Based upon the example above, I believe the exiftool part should be
exiftool -if "not $track and ExitDir()" %folder%
I can't advise on the goto skip part
Title: Re: Exiting directory on recursive conditional
Post by: georgejones314 on May 12, 2020, 03:31:54 PM
Thanks for the quick response. I followed your recommendation and got the following output:

    1 directories scanned
   17 files failed condition
    0 image files read
    1 directories scanned
   26 files failed condition
    0 image files read
...

It's as slow as the approach I'm trying to rewrite ... since it's apparently still reading every file in the directory in order to come up with the "17 files failed condition" line you see above ... Apparently the ExitDir isn't exiting.

Also, I don't want ANY output if a NO TRACK condition appears in any file (which is the vast majority of the files).

Thoughts?

The line I actually used was:
-if "not $track and ExitDir()" -charset filename=cp1252 %buffer%
Title: Re: Exiting directory on recursive conditional
Post by: Phil Harvey on May 12, 2020, 03:37:18 PM
The function is called EndDir() in ExifTool 11.96 and later.

- Phil

Edit: I just discovered that this feature doesn't work properly when the -v option is used.  I'll fix this in the next release.
Title: Re: Exiting directory on recursive conditional
Post by: georgejones314 on May 12, 2020, 04:18:31 PM
Thanks. I saw that you renamed it in the thread and then forgot to change it.
I look forward to the next release for -v
Perhaps there is a native ExifTool way to achieve my goal? The idea is to print out directories where ALL the files have something in the $track field. I currently count up all the nonblanks and compare to the total, but this takes 10 hours with my dataset. So I'm thinking:
1) EndDir at first encountered blank (I was planning on using GOTO)
2) If all are not blank then print out the directory name
Great product. Keep up the good work.
K
Title: Re: Exiting directory on recursive conditional
Post by: Phil Harvey on May 12, 2020, 04:26:37 PM
It would be easy to print the directory if a file was missing the specified tag, but I can't think of a way to easily do the inverse.

- Phil
Title: Re: Exiting directory on recursive conditional
Post by: georgejones314 on May 13, 2020, 12:34:20 PM
I'm not certain, but it appears there's no way to know if ENDDIR is getting invoked or the natural end of the directory has been reached by EXIFTOOL. I'm getting the same output in both instances, e.g.:

-if "not $track and EndDir()" -echo HELLO seem to say HELLO after the last file is read even if %track is present in all the files.

Thoughts?
Title: Re: Exiting directory on recursive conditional
Post by: Phil Harvey on May 13, 2020, 09:41:44 PM
EndDir() should print issue a warning to stderr when it is hit.  (If 11.99 doesn't, then this will be fixed in 12.00)

- Phil