View Full Version : AppleScript: Counting files of a certain type in a folder

May 4, 2005, 12:49 AM
I'm trying to count all the files of a certain type in a folder in an AppleScript I'm writing. Does anybody know how to do this. I can't count all the files in the folder with the following code:

set NoOfFiles to count each file in theFolder

But, I can't figure out how to only count a particular type of file (in this case FLAC files). Ideally I'd like a way to count files that have a particular extension, but counting based on the "kind" attribute in the finder would be ok too.

May 4, 2005, 01:09 AM
Try this:
tell application "Finder"
set NoOfFiles to count of (files in folder theFolder whose name extension is "flac")
end tell

May 4, 2005, 12:34 PM
Thanks for the reply. That worked perfectly.

May 4, 2005, 02:54 PM
Who needs applescript? ;)

ls -l *.flac | wc -l