This script creates a collection of the parent folders of the selected files. Ideally used on files in Find Results and Flat View. Makes it easy to work on folders based on their content, e.g. "move folders that contain mp3 files".
(Note to scriptheads: Gathering the paths in a StringSet before copying them to the collection greatly improves performance.)
function OnClick(clickData) {
var cmd = clickData.func.command;
var tab = clickData.func.sourcetab;
var parentFolders = DOpus.Create.StringSetI();
DOpus.ClearOutput();
DOpus.Output('Enumerating files...');
for (var e = new Enumerator(tab.selected_files); !e.atEnd(); e.moveNext()) {
var item = e.item();
DOpus.Output(item);
parentFolders.insert(item.path);
}
DOpus.Output('\nListing parent folders...');
cmd.ClearFiles();
for (var e = new Enumerator(parentFolders); !e.atEnd(); e.moveNext()) {
var item = e.item();
DOpus.Output(item);
cmd.AddFile(item);
}
cmd.RunCommand('Delete FILE="coll://Parentfolders" QUIET');
cmd.RunCommand('CreateFolder NAME="coll://Parentfolders"');
cmd.RunCommand('Copy TO="coll://Parentfolders" COPYTOCOLL=member');
cmd.RunCommand('Go PATH="coll://Parentfolders" NEWTAB=findexisting');
// or ditch the preceding commands and just run e.g.
// cmd.RunCommand('Copy MOVE');
DOpus.Output('\n... done');
}
Parents to Collection.dcf (2.4 KB)