How to count contents of multiple folders

Hey guys,


I have been looking for the answer to my question for awhile now, maybe you guys can help.


Here on my screenshot I have multiple folders selected.

I am looking for a program or script that will tell me how many files are in the selected folders.


I came across this script but it will only count (1) folder, not multiple.


tell application "Finder"

count files of entire contents of (choose folder)

end tell



User uploaded file

I have checked out Easy Find and couldnt get it to do what I want.



Thanks guys.

iMac, OS X Mavericks (10.9.5)

Posted on Feb 17, 2016 2:17 PM

Reply
6 replies

Feb 17, 2016 6:07 PM in response to VikingOSX

Ok. Got the code sorted. This was written and tested (again) on OS X 10.11.3 (El Capitan). It is working now. Second paragraph in my previous post — yes, copy/paste the following AppleScript code into your Script Editor, and continue to follow directions from that earlier post.


-- Select one or more folders in the Finder, and then run this script. It will cycle

-- through each selected folder, add the file count of the entire folder hierarchy,

-- and display the total file count for the folder selection.

-- VikingOSX, Feb. 17 2016, Apple Support Communities


set folder_list to {}

set file_cnt to 0


tell application "Finder"

if (number of items in my selection) = 0 then

display alert "You must select at least one directory ... " & return & "Quitting." as critical giving up after 10

error number -128

return

end if

set folder_list to selection


repeat with afolder from 1 to the number of items in folder_list

set file_cnt to file_cnt + (count of (every document file of entire contents of folder (item afolder of folder_list as text)))

end repeat

end tell

display dialog "Count of all files in all selected folders: " & file_cnt as text

return

Feb 17, 2016 6:08 PM in response to zsmithx

Select one of more folders in the Finder, and then just run this AppleScript. It will loop through each selected folder, and count every file in the selected folders hierarchy. A running total will be kept and when finished, a total file count will be displayed.


Copy/paste the following into your (Launchpad : Other : Script Editor), click the hammer icon to compile it, select a few folders, and click Run on the Toolbar.


You are looking at two save operations with the last giving you a clickable application on your Desktop:

  1. Source code save

    Save…

    1. Save As : hiercnt
    2. Location : Documents folder or wherever you want
    3. File format: Text (.applescript extension added to the Save As filename)
    4. Everything else is unchecked.
  2. Script save

    option + File menu : Save As…

    1. Save As: hiercnt
    2. Location: Desktop
    3. File format: Script, Script Bundle or Application (will add .scpt, scptd, or .app to filename)
    4. Check Hide Extension.
    5. All else unchecked


Code:

[You got to love code that consistently works until you post it. Update to come. /Viking]

Aug 18, 2016 8:00 AM in response to zsmithx

I found a very simple answer in the utility "duplicate detective" which is available in the apple app store for mac. Its not intended for this purpose but it does a perfect job of counting files in a hierarchy. Invoke the App, select hierarchy of interest and it scans and gives a total file count as its first step. I had a large photo store on a network drive. I selected the top folder of the hierarchy and let duplicate detective do its thing. In about two minutes, I had my file count (82,303).

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

How to count contents of multiple folders

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.