Image count by name and extension

This first script accomplishes what I am trying to achieve, but it is inefficient and is taking to much time to read through and update. I know there has to be a better way to write it, but I’m getting stumped.


tell application "Finder"
	set InBox to choose folder
	set acc1 to count (files in folder InBox where name begins with "031" and name extension is "tif")
	set acc2 to count (files in folder InBox where name begins with "032" and name extension is "tif")
	set acc3 to count (files in folder InBox where name begins with "033" and name extension is "tif")
	set acc4 to count (files in folder InBox where name begins with "034" and name extension is "tif")
	set acc5 to count (files in folder InBox where name begins with "035" and name extension is "tif")
	set acc6 to count (files in folder InBox where name begins with "036" and name extension is "tif")
	set acc7 to count (files in folder InBox where name begins with "094" and name extension is "tif")
	set acc8 to count (files in folder InBox where name begins with "104" and name extension is "tif")
	set acc9 to count (files in folder InBox where name begins with "122" and name extension is "tif")
	set acc10 to count (files in folder InBox where name begins with "131" and name extension is "tif")
	set acc11 to count (files in folder InBox where name begins with "132" and name extension is "tif")
	set acc12 to count (files in folder InBox where name begins with "133" and name extension is "tif")
	set acc13 to count (files in folder InBox where name begins with "134" and name extension is "tif")
	set acc14 to count (files in folder InBox where name begins with "135" and name extension is "tif")
	set acc15 to count (files in folder InBox where name begins with "143" and name extension is "tif")
	set acc16 to count (files in folder InBox where name begins with "222" and name extension is "tif")
	set acc17 to count (files in folder InBox where name begins with "228" and name extension is "tif")
	set acc18 to count (files in folder InBox where name begins with "229" and name extension is "tif")
	set acc19 to count (files in folder InBox where name begins with "230" and name extension is "tif")
	set acc20 to count (files in folder InBox where name begins with "231" and name extension is "tif")
	set acc21 to count (files in folder InBox where name begins with "233" and name extension is "tif")
	set acc22 to count (files in folder InBox where name begins with "234" and name extension is "tif")
	set acc23 to count (files in folder InBox where name begins with "235" and name extension is "tif")
	set acc24 to count (files in folder InBox where name begins with "322" and name extension is "tif")
	set acc25 to count (files in folder InBox where name begins with "331" and name extension is "tif")
	set acc26 to count (files in folder InBox where name begins with "333" and name extension is "tif")
	set acc27 to count (files in folder InBox where name begins with "422" and name extension is "tif")
	set acc28 to count (files in folder InBox where name begins with "433" and name extension is "tif")
	set acc29 to count (files in folder InBox where name begins with "443" and name extension is "tif")
	set acc30 to count (files in folder InBox where name begins with "533" and name extension is "tif")
	set acc31 to count (files in folder InBox where name begins with "743" and name extension is "tif")
	
	set acc to (acc1 + acc2 + acc3 + acc4 + acc5 + acc6 + acc7 + acc8 + acc9 + acc10 + acc11 + acc12 + acc13 + acc14 + acc15 + acc16 + acc17 + acc18 + acc19 + acc20 + acc21 + acc22 + acc23 + acc24 + acc25 + acc26 + acc27 + acc28 + acc29 + acc30 + acc31)
	
	
	
	set ImageTotal to (acc + 0)
	display dialog "" & ImageTotal & " image(s)"
end tell

My first attempt to stream line the script to make it less cumbersome is this:


set AccList to {"031" & "032" & "034" & "035" & "036" & "094" & "104" & "122" & "131" & "132" & "133" & "134" & "135" & "143" & "222" & "228" & "229" & "230" & "231" & "233" & "234" & "235" & "322" & "331" & "333" & "422" & "433" & "443" & "533" & "743"}

tell application "Finder"
	set InBox to choose folder
	set acc to count (get files in folder InBox where name begins with every item of AccList and name extension is "tif")
	set ImageTotal to (acc + 0)
	display dialog "" & ImageTotal & " image(s)"
end tell

The result always comes up as zero… I know there has to be some way to reference a list to search for files beggining with a specific name, but I don’t know how to go about it.

Thanks

Hi,

try this


set AccList to {"031" & "032" & "034" & "035" & "036" & "094" & "104" & "122" & "131" & "132" & "133" & "134" & "135" & "143" & "222" & "228" & "229" & "230" & "231" & "233" & "234" & "235" & "322" & "331" & "333" & "422" & "433" & "443" & "533" & "743"}

set acc to 0
set InBox to choose folder
tell application "Finder"
	repeat with i in AccList
		set acc to acc + (count (get files in InBox where name begins with i and name extension is "tif"))
	end repeat
	display dialog acc as text & " image(s)"
end tell

Thank you, that was the solution! The only thing I had to do was take the ampersands out of my list and replace them with commas. My fault.

This will save me tons of time not having to write a ridiculous number of lines in my script, thanks again! :smiley: