Add selected folders to the move queue as separate items

Actually, I am trying to make a button that adds all the selected files and/or folders to the named unattended move queue as separate items. The title was too long, I had to truncate :slight_smile:
I move terabytes of very large files and folders pretty much everyday. I would like to be able to add them to the queue as separate items, instead of a single move job which a couple terabytes. In case I need to stop the move - I simply delete the items from queue and let the current job finish, instead of canceling.

Anyway - I tried writing a script, and I get the the files moved, but all at once (not as separate jobs in queue) and dopus shows me errors like: "An unknown error occurred.", after its finished moving the files. huh.

Here's my code, what I'm doing wrong?

@script vbscript

Function OnCLick(ByRef ClickData)
	
	Dim cmd, selectedItems, source, destination

	Set cmd = ClickData.Func.command
	Set selectedItems = ClickData.Func.sourcetab.selected

	For Each item In selectedItems

		source = ClickData.Func.sourcetab.path & "\" & item.name
		destination = Chr(34) & ClickData.Func.desttab.path & "\" & item.name & Chr(34)

		DOpus.Output "source: " & source
		DOpus.Output "destin: " & destination
		DOpus.Output ""

		cmd.AddFile source   

		ClickData.func.command.RunCommand "Copy MOVE QUEUE=Unt1,quiet UNATTENDED=yes To=" & Chr(34) & destination & Chr(34)
		cmd.ClearFiles
	Next
End Function

Thanks in advance for any help.

ClickData.Func.command comes pre-populated with the selected items already added to it.

To make it work on different items, call cmd.ClearFiles before your loop. (Or move the cmd.ClearFiles at the end of the loop so it's done before the cmd.AddFile.)

Also, instead of:

source = ClickData.Func.sourcetab.path & "\" & item.name

Use:

source = item.realpath

That's less code, and it also gives you the right path for the file when in a virtual folder like Desktop, or when using Flat View and the file isn't directly below the source folder.

@leo, thank you.

It woks now. although it does not add all the selected files to the queue as queued jobs straight away, it moves them one by one. How can I make this script to NOT wait until the move is complete for current loop item?

The script now looks like this:

@script vbscript

Function OnCLick(ByRef ClickData)
	
	Dim cmd, selectedItems, source, destination

	Set cmd = ClickData.Func.command
	Set selectedItems = ClickData.Func.sourcetab.selected

	For Each item In selectedItems

		source = item.realpath
		destination = Chr(34) & ClickData.Func.desttab.path & "\" & item.name & Chr(34)

		DOpus.Output "source: " & source
		DOpus.Output "destin: " & destination
		DOpus.Output ""

		cmd.ClearFiles
		cmd.AddFile source   

		ClickData.func.command.RunCommand "Copy MOVE QUEUE=Unt1,quiet UNATTENDED=yes To=" & Chr(34) & destination & Chr(34)
		cmd.ClearFiles
	Next
End Function

I'm so sorry to bump this. But could someone help me with it, please. Maybe I'm having a "stupid moon faze or something" :slight_smile: but for the life of me, it seems I can't figure this out.
How do I make ClickData.func.command.RunCommand to add MOVE to the queue and NOT wait until it actually moves the files? So it could quickly loop through the selected list and add them to the queue?

This fixes a few errors, and uses dopusrt to run the command async:

[code]@script vbscript

Function OnClick(ByRef ClickData)

Dim cmd, selectedItems, source, destination

Set cmd = ClickData.Func.command
Set selectedItems = ClickData.Func.sourcetab.selected

cmd.ClearFiles

For Each item In selectedItems

  source = item.realpath
  destination = ClickData.Func.desttab.path

  cmd.RunCommand "dopusrt /acmd Copy MOVE QUEUE=Unt1,quiet UNATTENDED=yes TO=""" & destination & """ FILE=""" & source & """"

Next
End Function[/code]

However, I'd recommend not using this for the time being. Having tested it, I think there may be an issue that we need to investigate if things are rapidly added to the same queue in parallel. (I noticed that if a queued item is cancelled, it still gets copied in the background, which isn't right.)

For now, I would recommend not trying to do this at all, until we look into that.

@leo, thank You very much for your help.
I will not use it for now then. Where do I check/look for info on this issue in the future? I mean how should I find out that it is safe to use? I have needed this kind of button/script for a long time and will need it for the foreseeable future. I do A LOT of data moving on a daily basis.

Oh, and forgot to double check:

If I never cancel queued items, ie: I am sure, I will not need to cancel any queued copy/move operations, can I use your script now? If it's a potential issues only with canceling - I would very much like to use it now.
I mean, I very rarely need canceling, pretty much only when I myself make a mistake and queue items to be moved to the wrong tab :slight_smile:

Dopus is The best peace of software I have ever seen and used, btw. Well, Dopus or Visual Studio, but common that is not fare to even compare.

I'm not sure if it would be safe at the moment. That will depend on exactly what's going wrong.

We may update the thread if we find things, but otherwise the changes will always be included in the release notes for new versions.

@leo thanks for the answers