Find and count file type

Started by j99mac, June 12, 2021, 03:17:36 PM

Previous topic - Next topic

j99mac

I am looking to run a commend to find a .jpg or .gif in a directory or subdirectories and get the total count.
This what i have ""find . type f | grep -o ".[^.]+$" | sort | uniq -c"". What do i need to add to the script to have exclude directory folder00 when it dose the find?

Phil Harvey

WIth ExifTool you could do this:

exiftool -aaa -if '$filetype eq "JPEG"' DIR

It should list the files it finds, the print a summary like this:

    1 directories scanned
   82 files failed condition
   21 image files read


The last line tells you how many JPEG files it found.

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

greybeard

To exclude folder00 from your find command and pick up jpg or gif files it would be something like this:

find . -path "./folder00" -prune -false -o \( -name "*.jpg" -or -name "*.gif" \) -print 

I'm not sure exactly what you are trying to achieve

Luuk2005

Im also not understanding the exact goal, so this some more examples to experiment with using the exiftool...
To list all jpegs and gifs (not caring about file-extensions), and being prejudice against 'folder00' as the parent-folder...
exiftool -r -if '$filetype =~ /(JPEG|GIF)/ and $directory !~ /\/folder00$$/' -p '$filepath'  .

If only wanting the total-sentence from above, can pipe to sed like...
exiftool -v0 -r -if '$filetype =~ /(JPEG|GIF)/ and $directory !~ /\/folder00$$/' . |sed -n '$p'

If only wanting the total-number from above, can pipe to sed like...
exiftool -v0 -r -if '$filetype =~ /(JPEG|GIF)/ and $directory !~ /\/folder00$$/' . |sed -n '$s/ *\([0-9]*\).*/\1/p'

The commands are only being prejudice against parent-folder, so including images settled like... C:/path/folder00/AnotherFolder/image.ext
If to be prejudice against all folders named 'folder00' anywhere in the path, but also granting folders like 'aafolder00zz' ...
You can modify /\/folder00$$/ ===> /\/folder00($$|\/)/
Windows8.1-64bit,  exiftool-v12.84(standalone),  sed-v4.0.7

StarGeek

The -i (-Ignore) option would be better than using an -if as long as you're not looking for a partial directory name.

But the original question really was more a linux/Mac command line question, so maybe this belongs in Other Discussions?
* Did you read FAQ #3 and use the command listed there?
* Please use the Code button for exiftool code/output.
 
* Please include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).

Luuk2005

Greetings StarGeek and welcome back! I was worried that maybe something bad happens to you?
Im never used this -i option before, but -i folder00 seems much better to exclude images anywhere below any folder named 'folder00'.
So the first -if would really only be better, if wanting to be prejudice against 'folder00' only when its a parent-folder, so being very unlikely.

Im really no idea what is the exact goal, but glad to know about the -i option, because Im always just conducting this with -if instead.
Now looking at his question, Im also thinking maybe he just wanted a shell script? Anyways, its good that you are back now!
Windows8.1-64bit,  exiftool-v12.84(standalone),  sed-v4.0.7

StarGeek

Quote from: Luuk2005 on June 14, 2021, 06:54:35 PM
Greetings StarGeek and welcome back! I was worried that maybe something bad happens to you?

I have a failing HD the was intermittently corrupting files and was worried about losing thousands of pictures I've taken.  See this post.
* Did you read FAQ #3 and use the command listed there?
* Please use the Code button for exiftool code/output.
 
* Please include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).