GP SoftwareTwitter
Opus FAQsManualCommandsObjects

Parents to Collection

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)


2 Likes

I love the idea of the script, but I get weird behaviour (I'm fairly sure the script is doing to right thing).

Selecting a set file files in flat view, the ParentFolders button gives me a collection of the parents containing those file. Do it again with different set of files and you get a merged set of parent.

Hit refresh and its back to the original parent folders.

Navigate away, then back, and you see the correct set of parent folders.

If you close the parentfolders collection tab between tests, it works fine.

That looks like something we've already fixed for the next beta. Should be out this week. Please bump this if you still see the problem after that.