How would I calculate the size of a folder (including all contents)?

I tried using Get File Attribute but it seems to get the size of the individual folder and not all of the contents.

Put this script in an Execute AppleScript Action. It will return size of all items (files, folders, sub-folders) in the folder currently selected in the Finder.

use AppleScript version "2.5" -- El Capitan (10.11) or later
use framework "Foundation" -- this IS required
use scripting additions

## Some Scripts may work with Yosemite, but no guarantees ##
#  This script has been tested ONLY in macOS 10.11.6+

tell application "Finder" to set finderSelectionList to selection as alias list
set folderAlias to item 1 of finderSelectionList

--- Returns Entire Folder Size in Bytes ---
tell application "System Events" to set folderSize to size of folderAlias

--- Convert Bytes to Size-Appropriate Units as a String ---
set folderSize to (current application's NSByteCountFormatter's stringFromByteCount:folderSize countStyle:(current application's NSByteCountFormatterCountStyleDecimal)) as text

return folderSize
1 Like

Thanks!

@8times9,

If one of the above posts solves your problem/question as originally stated, please check the “Solved” checkbox (click for details) at the bottom of that post.

Otherwise, please post your remaining questions/issues about this problem.
If you have other questions, please start a new topic.

Hmm…looking at this, I’m not sure how I would integrate it into its intended use case in my macro.

I’m automatically importing files on CDs and copying them to Dropbox. Because I’m using a free account, my storage is limited to 2.4 GB, and trying to add any files once the limit is reached results in syncing halting.

My goal is to get the current size of the items in the Dropbox folder, add the value to the size of the file on the CD, and ensure the value is less than 2.4 GB.

The shell command “du” is what you need. This would give you a human-readable size of your desktop:

du -hs ~/Desktop

Leave out the “h” for a size in bytes.

1 Like

This should get you started. You need to confirm or change the first two actions that are in magenta, and to add the Actions you want to copy/move the file to DropBox.

##Macro Library   Check Folder Size Against Limits


####DOWNLOAD:
<a class="attachment" href="/uploads/default/original/3X/9/7/97008869d19620a9e4bf77cae0df1ba8ab2ca551.kmmacros">Check Folder Size Against Limits.kmmacros</a> (9.9 KB)
**Note: This Macro was uploaded in a DISABLED state. You must enable before it can be triggered.**

---



<img src="/uploads/default/original/3X/3/2/32fafb4cd9e86a6446f1e341b850382415d822c8.jpg" width="357" height="2000">

Questions?
2 Likes

With a few tweaks I integrated it into my current macro, thank you for taking the time to make it.