How to calculate the number of files in nested folders>

Hello -


I want to find out or calculate the number files nested within nested folders.


I'm assuming I would use Terminal or Apple Script, but I am not familiar with writing the lines of code to make the request. I would need to know what to copy into Apple Script, and then how to operate the script. (I am a long time mac-user 20 years, and have back-ups, but I DON'T WANT TO DELETE MY PICS because I didn't know how to run the script 😟


I'm looking to get a rough estimate of the number of photos I have in my Pictures album. I'm very particular about organizing files by year and date.


I use iPhoto occasionally, but loading all my pics into iPhoto would take forever and kill my disk space (despite the huge storage on machines these days.) iPhoto does exactly what I don't want it to do, it makes duplicates all over the place. If I want to go to the original file, it is a wild goose chase to hunt it down.


Yes there are a lot of helpful features, but for someone who uses Photoshop for work, and am contantly creating, and modifying photos, iPhoto is not my choice. I haven't looked at any other image databases in a while. I used to work with Cumulus, which 'linked' to the file without having to duplicate it.


I will sometimes use Adobe Bridge, but that can get clunky. So I have a collection of ways for searching files, none of them is completely ideal.


Thanks,


Beth😝

iMac, OS X Mavericks (10.9), 27" iMac, 17" MacBookPro, iPhone 5s

Posted on Feb 3, 2014 9:55 AM

Reply
21 replies

Dec 4, 2014 7:52 PM in response to Audio Perception

The following Terminal command should count all the files in folder 'test-directory' whose content does not end with 'my-text'.

The count excludes files with names starting with a dot.


d="/Users/me/test-directory"; t='my-text'; N=0; while read x; do [[ "$(tail -n 1 "$x")" = *$t ]] || ((N++)); done < <(find "$d" \! -name ".*" -type f); echo Number of files: $N ;

Dec 8, 2014 3:17 PM in response to Neville Hillyer

I have several aif and wav files in folders to count but I don't want to count any file names that end with -15 or -30.


This is what I have so far without filtering out file names ending with -15 or -30:


set theFolder to choose folder with prompt "Choose Folder to Count Files" default location alias (the path to pictures folder as text)


tell application "Finder"

set foldercount to count folders in the entire contents of theFolder

set filecount to count files in the entire contents of theFolder

end tell


display dialog "Folder Count: " & comma_delimit(foldercount) & "

File Count: " & comma_delimit(filecount)



on comma_delimit(this_number)

set this_number to this_number as string

if this_number contains "E" then set this_number to number_to_text(this_number)

set the num_length to the length of this_number

set the this_number to (the reverse of every character of this_number) as string

set the new_num to ""

repeat with i from 1 to the num_length

if i is the num_length or (i mod 3) is not 0 then

set the new_num to (character i of this_number & the new_num) as string

else

set the new_num to ("," & character i of this_number & the new_num) as string

end if

end repeat

return the new_num

end comma_delimit

Dec 8, 2014 4:16 PM in response to Audio Perception

Open the folder with your audio files in a Finder window. In the Finder Window search box, type the following to suppress the files containing -15, or -30 in their names. If you have the Finder status bar enabled, a count of files not matching the above will be displayed.


User uploaded fileUser uploaded file


The following AppleScript will return only the files found in the specific folder, and sub-folders that do not have a -15, or -30 in their filenames. The results come back as POSIX paths.


set myaudioPath to POSIX path of (path to home folder as text) & "Audio"

set myaudioList to {}


set myCMD to "mdfind -onlyin " & myaudioPath & " -name 'kMDItemFSName != \"*-15*\" && kMDItemFSName != \"*-30*\"'"


set myaudioList to do shell scriptmyCMD


display dialog (countparagraphs of myaudioList)

Dec 9, 2014 8:01 AM in response to Audio Perception

The following Terminal command counts all the files in folder hierarchy 'test-directory' whose file name does not start with a dot or end with -15 or -30. This will have to be modified if the names end with eg -30.wav.


d="/Users/me/test-directory"; find "$d" \! -name ".*" \! -name "*-15" \! -name "*-30" -type f | wc -l


Here is an AppleScript version:


set x to (do shell script "d=\"/Users/me/test-directory\"; \ find \"$d\" \\! -name \".*\" \\! -name \"*d\" \\! -name \"*l\" -type f | wc -l") display dialog "Number of files: " & x


It is preferable not to split the line after directory. It should be:


-directory\"; find

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 calculate the number of files in nested folders>

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