Copy into multiple selected destinations

Overview:

This script-button copies the selection from the source side in to each selected folder on the destination side.

Before clicking the button:

After clicking the button:

Download:

If you download button in .dcf format, you can drag & drop it straight to your toolbars. See near the end of How to add buttons from this forum to your toolbars.

Script code:

Here is the script code, to help those using the forum to find scripting techniques. You do not need to use or understand any of this if you just wish to use the button.

function OnClick(clickData)
{
	var source = clickData.func.sourcetab;
	var dest   = clickData.func.desttab;
	var cmd    = clickData.func.command;
	cmd.deselect = false; // Leave source files selected.

	if (typeof dest != "object"
	||	dest.selected_dirs.count == 0
	||	source.selected.count == 0)
	{
		clickData.func.dlg.Request("Need selections on both sides.","OK");
		return;
	}

	for (var e = new Enumerator(dest.selected_dirs); !e.atEnd(); e.moveNext())
	{
		cmd.AddLine("Copy TO=\"" + e.item().RealPath + "\"");
	}

	cmd.Run();
}
5 Likes

I don't seem to understand how to add my path to the button, Can anyone explain what is the correct format for it ?

The button/script will copy the files you select on the source side into each of the folders you select on the destination side.

If you want to copy things to a fixed path, there's a much easier way to do that. Assuming that's what you want, what are the path(s) you want to copy things to?

Yes you are correct, Im looking for an option to copy into fixed path

LIke this one C:\Users\vvovk\OneDrive - Teichert\Desktop\Working On

Is there any classes or tutorial for creating buttons or scripting them

The command would be:

Copy TO "C:\Users\vvovk\OneDrive - Teichert\Desktop\Working On"

See here for how to use it: How to use buttons and scripts from this forum

2 Likes

Thank you very match!

Could this be used to insert a file into multiple zip archives?

Yes, if you replace selected_dirs with selected.

1 Like

In Leo's script can it be made to move instead of copy
Tried changing Copy To=
To Copy Move TO= but it does not work

Moving into multiple destinations that way would not work. Once the files are moved into the first destination, they no longer exist to move into the second...

That would need to be done via a copy then a delete.

Changing the script to this should do that:

function OnClick(clickData)
{
	var source = clickData.func.sourcetab;
	var dest   = clickData.func.desttab;
	var cmd    = clickData.func.command;
	cmd.deselect = false; // Leave source files selected.

	if (typeof dest != "object"
	||	dest.selected_dirs.count == 0
	||	source.selected.count == 0)
	{
		clickData.func.dlg.Request("Need selections on both sides.","OK");
		return;
	}

	for (var e = new Enumerator(dest.selected_dirs); !e.atEnd(); e.moveNext())
	{
		cmd.AddLine("Copy TO=\"" + e.item().RealPath + "\"");
	}

	cmd.AddLine("Delete");
	cmd.Run();
}

Note that this is untested, so try it on some test source and destination folders first before trusting it to real data!

The only change is the cmd.AddLine("Delete"); line.

@Leo
Thanks for quick reply

It just deletes no copy

Not sure how that could be. You don't still have a "MOVE" in there from previous experimentation, do you?

Have just copied the complete modified script and it works Ok

Thanks for the help
As usual great support