Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

AleRod

macrumors newbie
Original poster
Sep 1, 2011
29
24
Hello,

Is there any app that count all the files by extension?
(mp4, mkv, mp3, flac, doc, xls, txt, . . . )

DaysiDisk and other similar apps only show information by kind and not particularly by file extension.

Thanks in advance for your help.
 
Not an app but using Terminal can do it easily Just change to the directory you wish to know the total of and use a command like this.

Code:
MacUser2525:/Volumes/Sea_To_Do/working/New_To_Convert/HB_Converted$ find . -name *.mkv | wc -l


      16

This uses the find command to search all directories under it (find .) and pipes (passes, the | ) the found files (-name *.mkv) to the word count (wc -l) to add the number of lines. The lines being a listing of a .mkv file found which is the total of them.

Edit Terminal can be found in the Applications/Utilites folder.
 
  • Like
Reactions: AleRod
I’d be willing to bet that this could be done with a bash script using the find command and a for loop.
 
Maybe it's not exactly what you'd like, but you could use Finder's Smart Folders to achieve that.

1. In Finder choose File -> New Smart Folder
2. Write the extension you'd like to the search field, for example ".mp4" and choose the option "Name matches .mp4"
3. Save the Smart Folder
4. Open the Smart Folder
5. Select all files
6. Right click the files and now you should see the amount of files you have with the certain file extension.

And then just create Smart Folder for every extension you like to see that way.

Good thing is that the folders doesn't move the files anywhere and that they update on their own, so you don't need to wait for any app to gather the information every time you want to see it.
 
thank you for your answers.

With your help and searching for some information I could find the next code that works for me:

Code:
find /Users//Documents/ -type f | sed -n 's/..*\.//p' | sort | uniq -c


the result:
Code:
   2 DS_Store
   1 jpg
 232 doc
   2 pdf
   1 flac
  10 xls
   2 txt


Now, the problem I have is I cannot figure it out how to exclude the hidden files like: DS_Store


I have some HDDs with many files inside folders and subfolders that I have to check.

An AppleScript would be great.

.
 
Last edited:
  • Like
Reactions: revmacian
thank you for your answers.

With your help and searching for some information I could find the next code that works for me:

Code:
find /Users//Documents/ -type f | sed -n 's/..*\.//p' | sort | uniq -c


the result:
Code:
   2 DS_Store
   1 jpg
232 doc
   2 pdf
   1 flac
  10 xls
   2 txt


Now, the problem I have is I cannot figure it out how to exclude the hidden files like: DS_Store


I have some HDDs with many files inside folders and subfolders that I have to check.

An AppleScript would be great.

.
Yeah, the find command is quite nice. I had a feeling a command line option would be easy to find online.
 
An AppleScript would be great.

I'd 100% be using the bash/command line route. But since you specifically asked about AppleScript then you could do it something like this.

Code:
set theInputFolder to choose folder
set theExtensionsToSearchFor to {"txt", "pdf"}
set fileNamesToOmit to {"testfile.pdf"}
set theResults to {}

repeat with theExtension in theExtensionsToSearchFor

    tell application "Finder"
        set theFiles to (every file of entire contents of folder theInputFolder whose name extension is theExtension and name is not in fileNamesToOmit)
        set theResults to theResults & {{|count|:count of theFiles, ext:theExtension as text}}
    end tell

end repeat
 
  • Like
Reactions: AleRod
I'd 100% be using the bash/command line route. But since you specifically asked about AppleScript then you could do it something like this.

Code:
set theInputFolder to choose folder
set theExtensionsToSearchFor to {"txt", "pdf"}
set fileNamesToOmit to {"testfile.pdf"}
set theResults to {}

repeat with theExtension in theExtensionsToSearchFor

    tell application "Finder"
        set theFiles to (every file of entire contents of folder theInputFolder whose name extension is theExtension and name is not in fileNamesToOmit)
        set theResults to theResults & {{|count|:count of theFiles, ext:theExtension as text}}
    end tell

end repeat


superscape, thank you very much. I will check it.
.
 
Just need to add a couple of params to the find. Not at the Mac right now, to test, but this should work:

Code:
find /Users/Documents -type f \! -name .DS_Store

ADD: or can add a grep after the find.

Code:
find parameters | egrep -v "DS_Store$|\.exe$|\.foo$|\.xyz$" | sed
 
Last edited:
Along the same lines, is there a Terminal command to tell one how many files there are on a certain drive? Ideally I'd like to run one command and have it return a file total for all drives connected to my Mac. But if I had to run the command seven times and add the result, that would be OK.

Thank you.
 
This seems to get everything but the cache on my external.

Code:
MacUser2525:~$ find /Volumes/Sea_To_D/ -type f | wc -l


find: /Volumes/Sea_To_D//.Spotlight-V100/Store-V2/456D6B27-6244-4E8D-A017-15F7949564A9/Cache: Permission denied


   38705
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.