zsmithx

Q: 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

 

 

Screen Shot 2016-02-17 at 5.12.50 PM.png


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

Close

Q: How to count contents of multiple folders

  • All replies
  • Helpful answers

  • by VikingOSX,Helpful

    VikingOSX VikingOSX Feb 17, 2016 6:08 PM in response to zsmithx
    Level 7 (20,799 points)
    Mac OS X
    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
      1. 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
      1. 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]

  • by zsmithx,

    zsmithx zsmithx Feb 17, 2016 5:35 PM in response to VikingOSX
    Level 1 (0 points)
    Feb 17, 2016 5:35 PM in response to VikingOSX

    I appreciate the reply, Is there anyway you can email me or send a quick video. I am a little confused on what I am copying and pasting? Am I pasting into the Apple script editor? Am I saving the operations so that I have the application?

     

    Thanks
    *******

     

    <Email Edited by Host>

  • by VikingOSX,Helpful

    VikingOSX VikingOSX Feb 17, 2016 6:07 PM in response to VikingOSX
    Level 7 (20,799 points)
    Mac OS X
    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

  • by zsmithx,

    zsmithx zsmithx Feb 17, 2016 5:54 PM in response to VikingOSX
    Level 1 (0 points)
    Feb 17, 2016 5:54 PM in response to VikingOSX

    Thank you! this worked perfectly.

     

    Final question, how do i use the applications once I saved them?

  • by VikingOSX,Solvedanswer

    VikingOSX VikingOSX Feb 17, 2016 6:12 PM in response to zsmithx
    Level 7 (20,799 points)
    Mac OS X
    Feb 17, 2016 6:12 PM in response to zsmithx

    Provided you did a Save As and put the script on your Desktop as a .scpt, .scptd, or .app, you can select the folders that you want to process, and then just double-click on the script, or application name on your Desktop. It will then process all folders that you selected, and give you a final file count.

  • by wrobertdavis,

    wrobertdavis wrobertdavis Aug 18, 2016 8:00 AM in response to zsmithx
    Level 1 (4 points)
    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).