Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Why does Apple count the folder as 1 when I want to know how many files there are in a folder?

This is something that has bothered me for years. I often include images to product test I do. And when I want to know if I have included all the images I am supposed to, I use folder info or cmd+I.

When I do I get the number of, in this case, the image files in the folder + the folder in I self. So if there are 10 image files the folder info tells me the folder contains 11 objects!!!

Why?

If I want to know how many files there are in a folder I obviously know that the folder exists right? So why tell me there is one and count it in the same way as a file. It makes no sense what so ever.

And No, I am not interested in work arounds, Apple scripts or third party software. This is something the operating system should solve.

Posted on May 4, 2021 2:07 AM

Reply
2 replies

May 4, 2021 6:17 AM in response to Northman

You selected the folder itself and when you perform a Get Info, it will include the folder in the count.


Here is an Automator Quick Action solution (that I named Folder File Count) that gets the count of files (not sub-folders) in a selected folder. You right-click on the folder, and from the Finder's secondary menu, you choose Quick Action > Folder File Count.



and the result for a folder containing 10 files is:



The Automator workflow looks like this:



and the replacement script code for the Run Shell Script action:


#!/bin/zsh

: <<'COMMENT'

Right-click on a folder and then from the Finder's contextual menu, select Quick Actions > Folder File Count.
Displays a dialog with the folder name and its contained file count.

COMMENT

typeset -a filecnt=()

function folder_count () {
    osascript <<AS
    display dialog "Folder: " & "${1}" & return & "Count: " & "${2}" ¬
    with title "File count for Folder"
AS
}

# handle tilde paths if run from Terminal
FOLDER="${1:a:s/\~\//}"

# ignore dot files (e.g. .DS_Store) and sub-directories
filecnt=( ${FOLDER}/*(N^/) )
# pass folder name and array count of files in folder
folder_count "${FOLDER:a:t}" ${#filecnt[@]}
unset filecnt
exit 0



Why does Apple count the folder as 1 when I want to know how many files there are in a folder?

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