Enumerate selected items into a simple line list

So I'm trying to build up a command to copy multiple selected items to a destination. This is part of the code:

if(scriptCmdData.func.sourcetab.selected.count == 0){Msg("Redo Operation: No Items Are Selected. Aborting..."); return;} enumSelected = new Enumerator(scriptCmdData.func.sourcetab.selected); enumSelected.moveFirst(); // enumerate the selected items in the tab while (enumSelected.atEnd() == false) { var cmd = DOpus.NewCommand(); cmd.AddLine('COPY '+'"'+enumSelected.item()+'"'+' TO '+'"'+ReOps_data_copy(ret-1)+'"'); cmd.Run; enumSelected.moveNext(); }I don't think it's good though since basically it's currently making a command for each individual file and then run it. How can I build up a single list of all the items and then build up the command with that list for the copy operation?

Somewhat unrelated but what's the DOpus.NewCommand? Why isn't it in the help manual? I figured out how to use it through examples but stuff like this is what I was talking about when I felt frustrated with using the manual.

I solved it with this:

if(scriptCmdData.func.sourcetab.selected.count == 0){Msg("Redo Operation: No Items Are Selected. Aborting..."); return;} enumSelected = new Enumerator(scriptCmdData.func.sourcetab.selected); enumSelected.moveFirst(); // enumerate the selected items in the tab while (enumSelected.atEnd() == false) { var selItems; if (selItems == null) {selItems = '"'+enumSelected.item()+'" ';} else {selItems = selItems+'"'+enumSelected.item()+'" ';} enumSelected.moveNext(); } /resource.dopus.com/viewtopic.php?t=22238 var cmd = DOpus.NewCommand(); cmd.AddLine('COPY '+selItems+'TO '+'"'+ReOps_data_copy(ret-1)+'"'); cmd.Run; }
But is that ideal?

DOpus.NewCommand is deprecated; new scripts should use the DOpusFactory object to create new command objects.

Instead of passing filenames on the command line it's better to add the files to the Command object directly. The "Adding a new Internal Command" example in the manual has an example of this.

For example,

var cmd = DOpus.Create.Command(); cmd.SetFiles(scriptCmdData.func.sourcetab.selected); cmd.RunCommand('COPY TO ' + '"' + ReOps_data_copy(ret-1) + '"');

Thanks! That makes it so much shorter than what I had.