Remove all files from a Collection

Is it possible to quickly remove all files and folders from a collection (and from all Sub-Collections in that collection).
I have a collection that is changing contents all the time (it's files I want to copy to my phone). Once I copy the files, I'd like a quick way to remove all the files and folders from the Collection, but leave all the Sub-Collections.

This is one of my buttons. It deletes the existing collection and copies selected files/folders to a newly created Collection with the same collection name (as the deleted collection. So it deletes and recreates the same collection in one step and adds the selected files.

Go 0_Red.dcf (668 Bytes)

1 Like

Unless the list of sub-collections is fixed, you'd probably need a script to clear everything from the collection and all sub-collections without also deleting the sub-collections themselves.

If the list of sub-collections is fixed then it's fairly easy.

Or you could have a button which deletes everything and then recreates new, empty (sub-)collections from a list of things you want created that would live in the button. That should also be quite simple.

1 Like

How about deleting with a filter?

Delete REMOVECOLLECTION FILTER NoCollection

With a filter NoCollection like this:

image

(Quick shot with little testing)

2 Likes

@Leo

Okay say the list of sub-collections is fixed. How could I do it?

lxp's suggestion looks better, if that works. I hadn't thought of that.

It works, but it isn't recursive -- you have to go into each sub-collection, select all, and run the button.

This script recursively removes all files and folders from a collection and its sub-collections:

function OnClick(clickData) {
    var cmd = clickData.func.command;
    var tab = clickData.func.sourcetab;
    cmd.RunCommand('Set UTILITY=otherlog');
    DOpus.ClearOutput;
    DOpus.Output('Items to be removed:\n');
    CleanCollection(tab.path);
    DOpus.Output('\n... done.');
}

function CleanCollection(coll) {
    var cmd = DOpus.Create.Command();
    var fsu = DOpus.FSUtil;
    var folderEnum = fsu.ReadDir(coll);
    while (!folderEnum.complete) {
        var fileItem = folderEnum.Next();
        if (String(fileItem.realpath).substr(0, 7) == 'coll:\/\/') {
            CleanCollection(fileItem.realpath);
        } else {
            var cmdLine = 'dopusrt \/col remove "' + coll + '" "' + fileItem.name + '"';
            DOpus.Output(cmdLine);
            // If you like the results, un-comment the following line
            // cmd.RunCommand(cmdLine);
        }
    }
}

RemoveFilesAndFoldersFromCollections.dcf (2.1 KB)

Note that you have to edit the script to actually remove files and folders.

2 Likes

@lxp
Hey thanks a lot, that's awesome!
Only problem is it doesn't work on files/folders with parentheses (maybe other wildcard characters too?).
I'm no Javascript expert, but my solution to escape all DOpus's wildcard characters was after this line:

var cmdLine = 'dopusrt \/col remove "' + coll + '" "' + fileItem.name + '"';

I added this line:

cmdLine = cmdLine.replace(/(\[|\]|\(|\)|\'|\~|\#)/g,'\'$1');

RemoveFilesAndFoldersFromCollections-wildcards-escaped.dcf (2.0 KB)

We'll add a scripting method to escape wildcard characters in the next update, to make things easier.

2 Likes