Button: Toggle size format


If you have Opus 12 or above then you may already have a slightly improved version of this script.

It is in the default menus under Edit > Toggle Size Format, and handles a few additional columns compared to the original version below.


This is a button/script which toggles the Size and/or Size-On-Disk columns between auto mode (showing bytes, KB, MB, GB, etc. depending on each size) and exact bytes.

I normally prefer the auto mode; it lets me quickly know how big something is without having to count how many digits there are. However, sometimes I need to see and compare sizes down to the exact byte. I don't want the exact sizes often enough to keep both columns visible at once, but the ability to quickly toggle between the two formats is ideal.

There are old versions of this button which just used a couple of non-scripting commands. They only toggled the Size column, not Size-On-Disk, and they only worked properly if Size was the second column. The script fixes both limitations and toggles the format of both columns wherever they are found.


  • Download Toggle Size Format.dcf (2.27 KB)
  • Select Settings -> Customize Toolbars.
  • Drag Toggle Size Format.dcf to where you want it on your toolbars or menus.
  • Click OK in the Customize window.


  • v1.0 16/Dec/2015 - First script version.

The script itself:

If you just want to use the script, the Toggle Size Format.dcf download above is probably easier.

The script code is reproduced here so people looking for scripting techniques can see the script code without downloading anything.

@script vbscript
Function OnClick(ByRef clickData)

	sizeIdx = -1
	sizeAutoIdx = -1
	disksizeIdx = -1
	disksizeAutoIdx = -1
	idx = 0

	For Each colItem in clickData.func.sourcetab.format.columns
		If (colItem.name = "size") Then sizeIdx = idx
		If (colItem.name = "sizeauto") Then sizeAutoIdx = idx
		If (colItem.name = "disksize") Then disksizeIdx = idx
		If (colItem.name = "disksizeauto") Then disksizeAutoIdx = idx
		idx = idx + 1

	Set cmd = clickData.func.command

	If (sizeIdx <> -1 And sizeAutoIdx = -1) Then
		cmd.RunCommand "Set COLUMNSREMOVE=size COLUMNSADD=sizeauto(" & sizeIdx & ")"
	ElseIf (sizeIdx = -1 And sizeAutoIdx <> -1) Then
		cmd.RunCommand "Set COLUMNSREMOVE=sizeauto COLUMNSADD=size(" & sizeAutoIdx & ")"
	End If
	If (disksizeIdx <> -1 And disksizeAutoIdx = -1) Then
		cmd.RunCommand "Set COLUMNSREMOVE=disksize COLUMNSADD=disksizeauto(" & disksizeIdx & ")"
	ElseIf (disksizeIdx = -1 And disksizeAutoIdx <> -1) Then
		cmd.RunCommand "Set COLUMNSREMOVE=disksizeauto COLUMNSADD=disksize(" & disksizeAutoIdx & ")"
	End If

End Function
1 Like

Very useful Leo! You hopefully don't mind showing my version of basically the same thing? o)
This one also remembers the column-widths and is easy to adjust to different sets of columns.

function OnClick(data) {
    ToggleColumns( "size",     "sizeauto",     data.func.sourcetab, data.func.command);
    ToggleColumns( "disksize", "disksizeauto", data.func.sourcetab, data.func.command);

function ToggleColumns(col01, col02, tab, cmd){
    var remCol = col01, addCol = col02, indexes = [], cols = tab.format.columns;
    for(var idx=0;idx<cols.count;idx++)	indexes[cols(idx).name.toLowerCase()] = idx+1;
    if (indexes[remCol] && !indexes[addCol]) var colIdx = indexes[remCol]-1;
    else if (!indexes[remCol] && indexes[addCol]) var remCol = col02, addCol = col01;
    else return;
    var colIdx = indexes[remCol]-1;	
    tab.vars.Set("TC.Width."+remCol) = cols(colIdx).width;
    var width = tab.vars.Exists("TC.Width."+addCol)?tab.vars.Get("TC.Width."+addCol):"*";
    cmd.RunCommand('Set COLUMNSREMOVE="'+remCol+'" COLUMNSADD="'+addCol+'('+(colIdx)+','+width+')"');