Copy files to many folders

Hello

I'm developing software and when a file is updated I wand to copy this file to several fixed locations. Lets say I change a file in C:\Inetpub\test\ I want to copy this file to \server\sites\Site1, \server\sites\Site2, \server\sites\Site3 and so on. But If I change a file in a subfolder like C:\Inetpub\test\scripts then I want it to be copied to \server\sites\Site1\scripts, \server\sites\Site2\scripts, \server\sites\Site3\scripts.

How can I do this with Dopus? I tried a little bit to make a script but got stuck when the file was in a subfolder from my test-site.

Thanks in advance Mattias

You want that to happen fully automatically or only after pressing a button of some kind?

Only when pressing a button. Only selected files should be copied.

Hopefully this will get you started. It may even do everything you need already, but I recommend doing some testing first.

Create a button, set Function: Script Function and change the language to JScript (if it isn't already), then paste this as the script:

[code]function OnClick(clickData)
{
// Remember to double all backslashes here.
var SourcePrefix = "C:\Inetpub\test";
var DestPrefixArray = new Array(
"\\server\sites\Site1",
"\\server\sites\Site2",
"\\server\sites\Site3"
);

// Resolve virtual path aliases like /desktop to a real folder.
var SourcePath = AddSlash(DOpus.FSUtil.Resolve(clickData.func.sourcetab.path));
SourcePrefix = AddSlash(SourcePrefix);

DOpus.Output("SourcePath: " + SourcePath);
DOpus.Output("SourcePrefix: " + SourcePrefix);

var SourceSuffix = "";

if (SourcePath.length >= SourcePrefix.length)
{
	if (SourcePath.substring(0,SourcePrefix.length).toLowerCase() == SourcePrefix.toLowerCase())
	{
		SourceSuffix = SourcePath.substring(SourcePrefix.length);
	}
}

if (SourceSuffix == "")
{
	clickData.Func.Dlg.Request("Used from unexpected source folder.", "OK", "Special Copy Script");
	return;
}

DOpus.Output("SourceSuffix: " + SourceSuffix);

var cmd = clickData.func.Command;
cmd.deselect = false;

for (var i = 0; i < DestPrefixArray.length; ++i)
{
	var DestPath = RemSlash(AddSlash(DestPrefixArray[i]) + SourceSuffix);
	var CmdLine = "Copy TO=\"" + DestPath + "\"";

	DOpus.Output("CmdLine: " + CmdLine);

	cmd.ClearFailed(); // Don't let failure stop a file being copied to other folders.

	// Uncomment this to actually run the copy commands:
	//cmd.RunCommand(CmdLine);
}

}

function AddSlash(s)
{
s = s + "";
if (s.length == 0 || s.substr(s.length-1) != '\')
s = s + '\';
return s;
}

function RemSlash(s)
{
s = s + "";
if (s.length != 0 && s.substr(s.length-1) == '\')
s = s.substr(0,s.length-1);
return s;
}[/code]

The cmd.RunCommand line is commented out, so you can run the script (push F5 or click the Run button in the button editor) to test it. There are some DOpus.Output lines which make it print what it is going to do.

If it's working correctly, it should print out some Copy TO="xyz" lines, which is what it would run if the RunCommand line was uncommented.

Let us know here if you get stuck anywhere.

Thanks a lot!! I had to make som modifications because it would not let me copy a file from the root (SourcePrefix path)

Kind regards Mattias