UPDATE: Here's the current code, which returns a 0, even when selecting a folder of jpg images
set f to (choose folder)
set posixF to POSIX path of f
set result to do shell script "find " & posixF & " -iname \"*.JPG\" | wc -l"
display dialog result
I need a way to count all of the JPG files in a collection of different folders. These folders are organized as so: Outermost folder -> Object folder -> either Scans (containing JPG files) or Originals (containing TIFF files). The outer folder can have up to hundreds of Object folders inside, hence the need for a script to count the files.
I have looked around for an applescript solution and the closest I have come only counts the number of JPGs in a single folder, not its subfolders. If I drop the outermost folder on the application, I get an output of 0, but if I drop one of the internal Scans folders, I get 10 (the actual number of JPG files in that test folder)
Here is what I have so far:
global currentCount
on open droppings
set NoOfFiles to 0
repeat with everyDrop in droppings
if (info for everyDrop)'s folder is true then
tell application "Finder"
set currentCount to (count of (files in folder everyDrop whose name extension is "jpg")) as integer
set NoOfFiles to NoOfFiles + currentCount
end tell
display dialog NoOfFiles
end if
end repeat
end open
on run
display dialog "Drop some folders onto the application to count the number of JPG files" buttons {"OK"} default button "OK"
end run
I have also tried adding some of this code into automator with the "Get Folder Contents" and "Repeat for each Subfolder found" option checked, but I get errors saying that applescript "couldn't make alias... something.tif into type folder".