Simple button Command to Copy file didn't work as hoped

Hi, I made a button in the Command Editor

@disablenosel @filesonly
Copy FILE C:\Templates\FF.txt HERE AS {file$} FORCE

It's supposed to copy the file FF.txt and rename it with the names of whatever files are selected. So I end up with N files in the current folder which have the contents of FF.txt without their filenames changing. I expected that this would work for many selected files. since I used "{file$}, but instead it only works for the first and deselects the others.

FF.txt just contains a single line of text. The characters "FF", so there are probably 101 other ways I could do this. But I'm new to programming DOpus so it would be nice to understand why this command didn't do what I expected.

This should be one way to do what you want:

dopusrt /acmd Copy FILE "C:\FF.txt" HERE AS {file$} FORCE QUEUE=none 

dopusrt is used to run the command as if it was an external command, which forces {file$} to work as expected. (Normally the Copy command will only run once, and work out itself which files to copy, even when using {file$} or similar as one of the arguments.)

Adding QUEUE=none also avoids waiting for the copy dialog to scroll for each separate copy command, although it also means all the copies may happen at once, which should be fine unless the template file is large and/or you're writing a very large number of files. (If that is the case, there are a few alternative ways to do the same thing which could avoid the issue.)

1 Like

Fantastic, thank you, yes that solved it. Plus I learned about dopusrt :slight_smile: