Close tabs when folder is deleted or moved

Give this little script a try. It uses the OnBeforeFolderChange event to intercept the folder change and close the tab.

function OnInit(initData) {
    initData.name = 'TabCloseIfParent';
    initData.version = '2024-05-27';
    initData.url = 'https://resource.dopus.com/t/close-tabs-when-folder-is-deleted-or-moved/50957';
    initData.desc = 'Close Tab instead of going to parent folder';
    initData.default_enable = true;
    initData.min_version = '12.0';
}

function OnBeforeFolderChange(beforeFolderChange) {
    if (beforeFolderChange.action != 'parent') return;
    var cmd = DOpus.Create().Command();
    cmd.SetSourceTab(beforeFolderChange.tab);
    cmd.RunCommand('Go TABCLOSE');
}

Save EventTabCloseIfParent.js.txt to   ↓

%appdata%\GPSoftware\Directory Opus\Script AddIns

How to use buttons and scripts from this forum


There's already the Preferences / Folder Tabs / Options / Close tab on device ejection option, so adding something like Close tab on folder delete doesn't seem too far off.