Question: Button for "Automated Folder Size"

is this possible ? I did not find any way but my skills in dopus-scripting are limited :slight_smile:


What do you want to do?

I want to toggle that option with a button, sorry if that was not clear.

I really need instant folder size calculation but not all the time so I keep it off for performance reasons normally. Beeing able to toggle that setting with a button would be nice.

I don't think we have a command to toggle that Preferences setting at the moment, but one could be added in the future. I could see it being useful sometimes as a quick toggle.

Usually you would keep the option off, and use Edit -> Calculate Folder Sizes (Ctrl + L) to calculate the sizes on-demand. (If nothing is selected, it'll calc. the sizes of all folders. If some folders are selected, it'll just calculate them.)

It's also possible to keep the option off in Preferences for most folders, but then override it for specific folders using Folder Formats. e.g. If you have a few small, quick to calculate folders where you often need to know their sizes, you might want to make it so Opus always calculates their sizes but doesn't for anywhere else. (If that would be useful but you're not sure how to set it up, ask and I'll go into more detail.)

I already have a button in my default toolbar to calculate folder size, but sometimes it is much more convenient to use the automatic calculation.
Thanks for the quick support & for considering my proposal :slight_smile:

I'm not sure if this is what you are referring to but @jon did this script not too long ago. I could not find the original post to reference but this button works great for calculating folder sizes with ease.

<?xml version="1.0"?>
<button backcol="none" display="icon" label_pos="right" textcol="none">
	<label>Smart GetSizes</label>
	<function type="script">
		<instruction>@script vbcript</instruction>
		<instruction />
		<instruction>Function OnClick(ByRef ClickData)</instruction>
		<instruction>   fGetAll = True</instruction>
		<instruction>   for each file in ClickData.Func.Command.files</instruction>
		<instruction>      if file.is_dir and (not file.got_size) Then</instruction>
		<instruction>         fGetAll = False</instruction>
		<instruction>         exit for</instruction>
		<instruction>      end if</instruction>
		<instruction>   next</instruction>
		<instruction>   if fGetAll Then ClickData.Func.Command.ClearFiles</instruction>
		<instruction>   ClickData.Func.Command.deselect = False</instruction>
		<instruction>   ClickData.Func.Command.RunCommand &quot;GetSizes&quot;</instruction>
		<instruction>End Function</instruction>

Here is the original post with that script, which also explains what the script does differently to the normal Calculate Folder Sizes (Ctrl+L) command.

This is a nice replacement for the ctrl-l behavior, thnks.
but it does not help with my request.

+1 for a command that turns foldersize-calculation on/off.

A new Set CALCFOLDERSIZES command has been added for Opus 11 beta 5 (note: not out yet; we just released beta 4) which can be used to toggle the Preferences option.


Really? After I juuuuust wrote this?

' OnAfterFolderChange_getsizes:
' Revision:    1.0.3
' (c) 2014 steje
' This is a script for Directory Opus.
' See for development information.

' This script is intended to provide a way of simulating the ability to 'toggle' the
' 'Calculate folder sizes automatically' option in Prefs. It works by checking if a
' lister scoped variable named 'autosize' is set, which should be set and unset as
' needed using a normal Opus hotkey or button using the @set directive...
' This version of the script currently operates on any type of folder, and doesn't
' currently offer the granularity of control of the actual Prefs option...
' Note also that this version of the script also operates on a per lister basis...

DEBUG = false

' Called by Directory Opus to initialize the script
Function OnInit(ByRef initData)

   ' Provide basic information about the Script = "OnAfterFolderChange_getsizes"
   initData.desc = "Check for lister variable on folder changes to auto-calculate folder sizes or not"
   initData.copyright = "(c) 2014 steje"
   initData.default_enable = true

End Function

' Called whenever the folder is changed
Function OnAfterFolderChange(ByRef afterFolderChangeData)

   ' Check if the folder read was successful
   if afterFolderChangeData.result Then
      Set objCmd = DOpus.CreateCommand
      if objCmd.IsSet("$lst:autosize") Then
         logMsg("The 'autosize' lister variable is set!")
         ' Clear the list of files that objCmd.RunCommand will operate on in case the 'Automatically select first file in folder' Prefs option is set
         logMsg("The 'autosize' lister variable is NOT set!")
      end if
      Set objCmd = Nothing
   end if

End Function

' Subroutine to allow toggling of the global DEBUG variable to control whether logging is performed or not
Sub logMsg(ByRef message)

   if (DEBUG) Then
   end if

End Sub


Doh! Neat script, though.

Thanks, maybe woulda been neater if you hadn't made it obsolete before I even got a chance to post it :slight_smile:... lol

Maybe I'll post it to the Scripting forum anyway as another example of an Event driven script. I can see stuff "like" this being useful in general... particularly if you guys entertain the request to toggle button on/off/highlight state based on @set vars -> DO11: [FR] Test @set variables with @toggle?

Yours is still useful because it's Lister-local rather than a global setting.

Plus it's a nice example :slight_smile:

Ah, well that makes me feel better :slight_smile:. To your point, this is one of the aspects to your scripting enhancements that I find REALLY promising. The prospect of having the ability to make subtle behavioral modifications or extensions to things that may already be possible in Opus to some degree ourselves or for other users, without having to continue barraging you guys with endless feature requests.

So stoked with what you've done to make these things possible!

Ditto. And I hope to see many more interesting ideas posted to the Scripting forum. I have been doing a bit of experimenting too and except to have something in a fit state (i.e. properly documented) to add soon. I'm sure we can all learn a lot from each other.

Regards, AB

I've got a few sample script ready to share - but would like to package into an OSP. Just wondering about how to specify the icon for a .OSP archive.

thx @ leo + steje

Dumb question: how can I use the new switch ?

Set CALCFOLDERSIZES=toggle seems to do nothing here (actually no parameter seems to change anything)