GP SoftwareTwitter
Opus FAQsManualCommandsObjects

Sort folders on top except when sorted by "Modified"

I list folders and files separately. I would like folders to be listed on top except in the case where I'm sorting a list by "modified". In other words, once a lister is sorted by "modified" (whether manually or as a saved default) the folders should group at the bottom. Is it possible to do this?

I don't think this can be directly set in the settings (except in Folder Formats), but you could use a button that combines the two commands and/or have a Script Add-in do it after a folder change.

Set SORTBY=modified
Set SORTORDER=files

(See Raw Commands in How to use buttons and scripts from this forum)

// FoldersDownIfSortedByModified

// This is a script for Directory Opus.
// See https://www.gpsoft.com.au/DScripts/redirect.asp?page=scripts for development information.

// Called by Directory Opus to initialize the script
function OnInit(initData) {
    initData.name = 'FoldersDownIfSortedByModified';
    initData.default_enable = true;
    initData.min_version = '12.0';
}

// Called after a new folder is read in a tab
function OnAfterFolderChange(afterFolderChangeData) {
    var cmd = DOpus.Create.Command;
    cmd.SetSourceTab(afterFolderChangeData.tab);
    if (afterFolderChangeData.tab.format.sort_field == 'modified') {
        cmd.RunCommand('Set SORTORDER=files');
    } else {
        cmd.RunCommand('Set SORTORDER=folders');
    }
}

FoldersDownIfSortedByModified.js.txt (726 Bytes)

(Download, then drag the file to the list in Preferences / Toolbars / Scripts.)

1 Like

(I've added one line running cmd.SetSourceTab ... to the script above which should help when folders open int he background. Edited in the post to keep things tidy.)

Going back to the button before the script, you could make it into a toggle like this:

@if:Set SORTBY=modified
Set SORTBY=name
Set SORTORDER=folders
@if:else
Set SORTBY=modified
Set SORTORDER=files

If you click it when sorting by anything other than Modified, it will switch to showing files before folders, and sorting by modified.

If you click it when already sorting by Modified, it will switch to showing folders before files and sorting by name.

1 Like

Thanks for the detailed guidance! It works.

1 Like