Scripting: How to remove item/all items from collection?

Using JScript I can create a collection with

var command = DOpus.NewCommand;
command.RunCommand("CreateFolder coll://MyCollection");

and add files to this collection using

command.RunCommand("Copy <file_path> TO coll://MyCollection");

but how can I remove a single item or all items from this collection, without actually removing the collection itself ?

I've tried Delete coll://MyCollection.

You want to add the REMOVECOLLECTION argument to the Delete command to make it remove from collections instead of deleting.

If I do Delete REMOVECOLLECTION coll://MyCollection it doesn't delete any entries.

If you want to clear the whole collection, just delete the collection itself and then re-create it. That's the quickest and easiest way.

What about for removing individual items ?

That's more complicated, because you need to exactly specify the full (non-collection) paths of the items you want to remove, while running the command in the context of the collection.

(Since a collection may have two file with the same name, you can't just specify a path like "coll://MyCollection/file.txt" as it may be ambiguous.)

Here's an example which removes three files from the Find Results collection, two of which have the same name:

var command = DOpus.NewCommand; command.SetSource("coll://Find Results"); command.AddFile("C:\\Users\\Leo\\Desktop\\obliv25kl.jpg"); command.AddFile("D:\\Images\\_unsorted_3\\obliv25kl.jpg"); command.AddFile("D:\\Images\\_unsorted_3\\Oblivion7.png"); command.RunCommand("Delete REMOVECOLLECTION");