Adding/removing files to/from command object

AddFile(item) can add an item more than once to a command object.

This can cause problems, e.g. when using Copy MOVE. The first entry will be moved correctly, the second one will fail. Wouldn't it be useful to always keep the list of files in the command object unique?

RemoveFile(item) will throw an error, if the item is not in the command object.

I can check before I remove, but wouldn't it make more sense, if no error happened?

1 Like

Could you use a StringSet or similar to test if you're already added a path to the list?

We'd need to do something similar on our side to change things, but if we do it there then every script is always paying for the extra overhead when it's not usually needed.

Another option on our side might be a method to remove duplicates, or a switch to turn on testing for them, but having the script test a secondary StringSet before insertion should be fairly simple as well.

Yes, the additional overhead is a good reason not to check every time, and a check via StringSet is easy.

Out of curiosity: would an internal routine be much faster than a bit of JScript?

Doing it internally would remove some overheads (each call between script and object has some overhead, and may need the strings to be copied/wrapped into other objects internally), but probably wouldn't make a big difference unless there's a huge number of files.