AppleScript: Counting files of a certain type in a folder

Discussion in 'Mac Programming' started by mduser63, May 3, 2005.

  1. macrumors 68040

    mduser63

    Joined:
    Nov 9, 2004
    Location:
    Salt Lake City, UT
    #1
    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.
     
  2. Administrator

    HexMonkey

    Staff Member

    Joined:
    Feb 5, 2004
    Location:
    New Zealand
    #2
    Try this:
    Code:
    tell application "Finder"
    	set NoOfFiles to count of (files in folder theFolder whose name extension is "flac")
    end tell
     
  3. thread starter macrumors 68040

    mduser63

    Joined:
    Nov 9, 2004
    Location:
    Salt Lake City, UT
  4. macrumors 603

    jeremy.king

    Joined:
    Jul 23, 2002
    Location:
    Fuquay Varina, NC
    #4
    Who needs applescript? ;)

    Code:
    ls -l *.flac | wc -l
     

Share This Page