# SmartGetSizes: Script Command to calculate folder sizes

**URL:** <https://resource.dopus.com/t/smartgetsizes-script-command-to-calculate-folder-sizes/17945>\
**Category:** Buttons/Scripts\
**Tags:** script, commands, vbscript\
**Created:** [March 28, 2014, 5:46pm UTC](https://resource.dopus.com/t/smartgetsizes-script-command-to-calculate-folder-sizes/17945 "2014-03-28T17:46:10Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![steje](https://resource.dopus.com/user_avatar/resource.dopus.com/steje/32/26008_2.png) [@steje](https://resource.dopus.com/u/steje)\
**Post date:** [March 28, 2014, 5:46pm UTC](https://resource.dopus.com/t/smartgetsizes-script-command-to-calculate-folder-sizes/17945/1 "2014-03-28T17:46:10Z")

</div>

Requires Opus 11.16 or above.

This script was written as part of another request described in the following discussion:

> [@SmartGetSizes\_Handler: Toggle automatic folder size calculation](https://resource.dopus.com/t/smartgetsizes-handler-toggle-automatic-folder-size-calculation/17123/1):
>
> Requires Opus version 11.16 or above. This was as much an excuse to share an example of what could be done using the cool new scripting interfaces in Opus v11 as it was to provide something of potential use to others. It came from discussions in sev…

...but I thought that just this piece of that idea might be of interest to others on it's own.

What does it do?:

This script adds a 'SmartGetSizes' Script Command to Opus. Such commands can be used like any other Opus internal commands directly in toolbar buttons, hotkeys, etc. On first run, SmartGetSizes will calculate the sizes of any selected folders (and all folders if none are selected)... just like the built-in GetSizes command. From there, it differs from the built-in GetSizes command in several ways:

- If all selected folders have already had their sizes calculated, running the command a second time will subsequently calculate the rest of the folder sizes in the current dir (as would happen if you had run the regular GetSizes command with either ALL or NONE of the folders selected).

- If all selected folders have already had their sizes calculated, and you then select one or more additional folders, running the command again will only calculate the sizes of the newly selected folders. Running the command yet again without changing any selections will work as just mentioned above in the first bullet.

- The command supports the use of a NODESELECT option just like the built-in GetSizes command... but also supports a GETALL option as well which forces size calculation of all folders in the current dir regardless of either selection status or existing size calculation.

Note: credit to Jonathan Potter, who wrote the working code that inspired this script command as an early example of a script function to solve the needs of the user in the following discussion:

> [@DO11: folder sizes shortcut behavior vs. DO10](https://resource.dopus.com/t/do11-folder-sizes-shortcut-behavior-vs-do10/16792/1):
>
> In Opus 10 if we press CTRL+L twice while some folder is selected it will calculate folder sizes of all folders in that lister rather than just of selected folder. In DO11 this doesn't work that way, we have to deselect any selected folder(s) first i…

How to install and use it?:

The script is provided here as an _Opus Script Package_, which in turn is actually a zip file with a single VBScript packaged inside.

- Download: [SmartGetSizes (vb).osp](https://resource.dopus.com/uploads/default/original/3X/4/f/4f91bbae0ad429e44dcd73117f990b3a2a5a4e75.osp) (1.99 KB)

Notes:

- 2014-03-28: Initial release...
- 2014-06-05: v1.0.5 - the VBScript version was updated. The update fixes a missing variable declaration noticed by qiuqiu (thanks again).
- 2015-12-27: v1.2.0 - scripts renamed to match my new standard, also added a DEBUG\_CLEAR option to clear the output log between script runs, and minimum required Opus version is now set to 11.16.
- 2016-11-22: v1.2.2 - Fixed an issue with an incorrect variable name and logic error when one or more selected folders did not have it's size already calculated. NOTE: that with this latest version, I am only maintaining the VBscript version. However, I've left the previous Jscript version 1.2.0 posted for posterity.

The script package can be installed by either manually copying the OSP file to the `/dopusdata\Script AddIns` folder, or via drag-and-drop into the Preferences / Toolbars / Scripts page.

 ![](https://resource.dopus.com/uploads/default/original/2X/5/50167aa8bfce1def21f9b533c8483afac4fa1a7d.png)

The only script configuration options available are the DEBUG and DEBUG\_CLEAR options that control logging of messages to the Opus Output Window.

![](https://resource.dopus.com/uploads/default/original/2X/2/2e75cc9fa6af1d6d49b4d5868ed7b263d754ac82.png)

After installing the script package, you can then use the command just like any other Opus command:

 ![](https://resource.dopus.com/uploads/default/original/2X/f/fdda78579e96bfec58f42c56bebb054ce1354654.png)

---

<div class="post-metadata">

**Author:** ![qiuqiu](https://resource.dopus.com/user_avatar/resource.dopus.com/qiuqiu/32/55961_2.png) [@qiuqiu](https://resource.dopus.com/u/qiuqiu)\
**Post date:** [June 4, 2014, 3:20am UTC](https://resource.dopus.com/t/smartgetsizes-script-command-to-calculate-folder-sizes/17945/2 "2014-06-04T03:20:29Z")

</div>

ScriptCommand\_SmartGetSizes (vb).osp

ScriptCommand\_SmartGetSizes: 发生错误于 88,位置 7  
ScriptCommand\_SmartGetSizes: 变量未定义: 'file' (0x800a01f4)

68行改为  
Dim fGetAll, fNoDeselect, objCmd, file

---

<div class="post-metadata">

**Author:** ![steje](https://resource.dopus.com/user_avatar/resource.dopus.com/steje/32/26008_2.png) [@steje](https://resource.dopus.com/u/steje)\
**Post date:** [June 5, 2014, 7:04pm UTC](https://resource.dopus.com/t/smartgetsizes-script-command-to-calculate-folder-sizes/17945/3 "2014-06-05T19:04:10Z")

</div>

Thanks... not sure how I missed that during final testing before posting. Hmmm...

I'm updating the root post with a fixed version of the script, and will make the same update to the version in the original script this was packaged with.

---

<div class="post-metadata">

**Author:** ![steje](https://resource.dopus.com/user_avatar/resource.dopus.com/steje/32/26008_2.png) [@steje](https://resource.dopus.com/u/steje)\
**Post date:** [December 28, 2015, 12:14am UTC](https://resource.dopus.com/t/smartgetsizes-script-command-to-calculate-folder-sizes/17945/4 "2015-12-28T00:14:27Z")

</div>

Root post updated with new version... no ~functional change other than some renaming of scripts to match a new standard I've settled on as well as added an option to clear log messages between script runs.

---

<div class="post-metadata">

**Author:** ![steje](https://resource.dopus.com/user_avatar/resource.dopus.com/steje/32/26008_2.png) [@steje](https://resource.dopus.com/u/steje)\
**Post date:** [November 24, 2016, 3:29am UTC](https://resource.dopus.com/t/smartgetsizes-script-command-to-calculate-folder-sizes/17945/5 "2016-11-24T03:29:16Z")

</div>

Root post updated with a few small corrections.
