MergeFolders combines the contents of selected folders or file collections into a chosen destination, which can be selected from a drop-down menu.
The Switch button alternates the drop-down menu display between the folders' names and their paths.
How to set up and use
Save CommandMergeFolders.js.txt to ↓
%appdata%\GPSoftware\Directory Opus\Script AddIns
Add the new command to a button, hotkey, context menu, etc. like any built-in command, or run it from the FAYT Command field.
Things you might enjoy reading
How to use buttons and scripts from this forum
The script's inner workings
JScript
function OnInit(initData) {
initData.name = 'MergeFolders';
initData.version = '2024-02-23';
initData.url = 'https://resource.dopus.com/t/merge-folders-and-collections/41476';
initData.desc = 'MergeFolders';
initData.default_enable = true;
initData.min_version = '12.0';
}
function OnAddCommands(addCmdData) {
var cmd = addCmdData.AddCommand();
cmd.name = 'MergeFolders';
cmd.method = 'OnMergeFolders';
cmd.desc = 'Merge Folders and Collections';
cmd.label = 'MergeFolders';
cmd.hide = false;
cmd.icon = 'script';
}
function OnMergeFolders(scriptCmdData) {
var cmd = scriptCmdData.func.command;
var tab = scriptCmdData.func.sourcetab;
var dlg = scriptCmdData.func.Dlg();
var fsu = DOpus.FSUtil();
cmd.deselect = false;
if (tab.selected_dirs.count < 2) {
dlg.Request('Please select at least two folders!', 'OK');
return;
}
var dirItems = DOpus.Create().Vector();
var dirNames = DOpus.Create().Vector();
for (var e = new Enumerator(tab.selected_dirs); !e.atEnd(); e.moveNext()) {
var item = e.item();
dirItems.push_back(item);
dirNames.push_back(item.name);
}
dlg.title = 'Merge Folders';
dlg.message = 'Please select the destination folder:';
dlg.buttons = 'OK|&Switch|Cancel';
dlg.selection = 0;
var showPath = false;
do {
dlg.choices = showPath ? dirItems : dirNames;
var userChoice = dlg.Show();
if (userChoice == 2) showPath = !showPath;
} while (userChoice == 2);
if (userChoice != 1) return;
var s = dlg.selection;
var dstPath = dirItems(s).path;
var dstFolder = dirItems(s).name;
var dstColl = dirItems(s);
dirItems.erase(s);
if (String(dstPath).substring(0, 5) == 'coll:') {
for (var e = new Enumerator(dirItems); !e.atEnd(); e.moveNext()) {
var coll = e.item();
cmd.SetFiles(fsu.ReadDir(coll).Next(-1));
cmd.RunCommand('Copy' +
' TO="' + dstColl + '"' +
' COPYTOCOLL=member');
}
cmd.SetFiles(dirItems);
cmd.RunCommand('Delete QUIET');
} else {
cmd.SetFiles(dirItems);
cmd.RunCommand('Copy' +
' MOVE' +
' AS="' + dstFolder + '"' +
' TO="' + dstPath + '"' +
' WHENEXISTS=rename,merge');
cmd.RunCommand('Go' +
' PATH="' + dstPath + '\\' + dstFolder + '"' +
' OPENCONTAINER');
}
}