Exiting directory on recursive conditional

Started by Tom Cunningham, April 21, 2020, 11:59:09 PM

Previous topic - Next topic

Tom Cunningham

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?

Phil Harvey

#1
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.
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

Phil Harvey

...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

Phil Harvey

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
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

Tom Cunningham

Works great, Phil, thanks!  End() and EndDir() are fine with me; will that be in 11.96?

Phil Harvey

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
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

Phil Harvey

...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

georgejones314

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

StarGeek

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
"It didn't work" isn't helpful. What was the exact command used and the output.
Read FAQ #3 and use that cmd
Please use the Code button for exiftool output

Please include your OS/Exiftool version/filetype

georgejones314

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%

Phil Harvey

#10
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.
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

georgejones314

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

Phil Harvey

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
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

georgejones314

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?

Phil Harvey

#14
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
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).