ExifTool Forum

ExifTool => The "exiftool" Application => Topic started by: georgejones314 on April 17, 2017, 06:10:21 PM

Title: Count of items matching a search criteria
Post by: georgejones314 on April 17, 2017, 06:10:21 PM
I'm building a simple batch file to compare the total count of files in a directory to the count of files matching -if "$track". if track is present then i have listened to the item (mp3)... and if the total count for track = total items then i have finished the album (directory).

Is there a simple way to count the items that match the -if "$track" criteria?

Thanks
Keith

Sorry if this is obvious, but I spent the appropriate amount of time searching the documentation and forum and came up empty handed.
Title: Re: Count of items matching a search criteria
Post by: StarGeek on April 17, 2017, 06:45:42 PM
I think the easiest way would be to pipe the exiftool output into grep (or find for windows) and take the "files read" line that appears at the end. 

exiftool -if "$track" -PlaceholderTag FileOrDir | grep "files read"

Replace grep with find for windows.  I just put "PlaceholderTag" in there as a fake tag to limit the output of exiftool.
Title: Re: Count of items matching a search criteria
Post by: georgejones314 on April 18, 2017, 12:40:16 PM
Thanks I'll give it a try and report back.
Keith
Title: Re: Count of items matching a search criteria
Post by: georgejones314 on April 19, 2017, 12:40:06 PM
The following subroutine worked, but yuch! I hate writing to a temporary file in a batch process. But since I only run this once a year or so, it's not that big a deal.

Thx


:subroutinecompare
REM Search each directory for any podcast having an entry in the track field
REM Compare count of files with track field to total files in directory
REM If equal then the album (directory) is finished (i'm done listening to the album)
setlocal EnableDelayed Expansion
c:\exiftool.exe -if "$track" -L -track !directory!>>c:\temp.m3u8
FOR /F "tokens=1 USEBACKQ" %%i IN (`find "files read" c:\temp.m3u8`) DO (SET done=%%i)
for %%x in (!directory!\*.mp3) do set /a count+=1
if !done! equ !count! echo !folder!>>c:\Finished.m3u8
endlocal
EXIT /b