Copy Replace question

I don't know how to word this so I will try to give an example.

I have a source file src.nif I want to copy it then replace some target files with its contents.

Before:
src.nif
target1.nif unique content
targetb.nif unique content
targetsefee.nif unique content

After:
src.nif
target1.nif contents of src.nif
targetb.nif contents of src.nif
targetsefee.nif contents of src.nif

Is there already something that can do this?

Edit:
I just made a button with this command Copy c:\test\src.nif {allfilepath} and I also tried {filepath} . Didn't work. The error: An error occurred copying 'Quick': the system cannot find the file specified. I also tried with the full path of the destination, same problem

Copy "src.nif" WHENEXISTS=replace HERE AS="target1.nif"
Copy "src.nif" WHENEXISTS=replace HERE AS="targetb.nif"
Copy "src.nif" WHENEXISTS=replace HERE AS="targetsefee.nif"

That will replace the three files without confirmation, so be careful.

You could add a line with @confirm on it if you want confirmation.

(Or remove the WHENEXISTS=replace, but then you'd be prompted three times instead of just once.)

is there a way to get the destination file based on it being selected when I click the button? It seemed like {allfilepath} or {filepath} does that.

If not I guess I can write a script and use Tab.selected then iterate over it.

That's what I would do if you need it to work like that. (There is a way you could do it without a script, but I don't think it would be a good solution vs a script.)

Using a script also makes it easier to make this work with files selected in sub-folders via Expandable Folders / Flat View / etc.

Something like this should do what you want:

function OnClick(clickData)
{
	var srcFile = "src.nif";
	var cmd = clickData.func.command;
	// cmd.deselect = false;
	for (var eSel = new Enumerator(clickData.func.sourcetab.selected_files); !eSel.atEnd(); eSel.moveNext())
	{
		var item = eSel.item();
		if (item.name == srcFile)
			continue; // Don't try to copy srcFile over itself.
		var cmdLine = 'Copy "' + srcFile + '" TO="' + item.Path + '" AS="' + item.Name + '" WHENEXISTS=replace';
	//	DOpus.Output(cmdLine);
		cmd.AddLine(cmdLine);
	}
	if (cmd.linecount > 0)
		cmd.Run();	
}
1 Like

Well that still throws errors.
Here is the actual code of the button

Copy C:\test\cap.nif WHENEXISTS=replace HERE AS "\\AMD\QuadTB\Quick Configuration v1.8.4h1 - Portable-546-1-8-4h1-1600638167\mods\caps_plants\meshes\landscape\plants\tatoplant01.nif"

without qoutes

Copy C:\test\cap.nif WHENEXISTS=replace HERE AS \\AMD\QuadTB\Quick Configuration v1.8.4h1 - Portable-546-1-8-4h1-1600638167\mods\caps_plants\meshes\landscape\plants\tatoplant01.nif

AS takes a name, not a path. Use TO to change the destination path.

The script I posted (while you were writing your reply, so maybe not seen yet) handles it.

1 Like

Oh, page must not have updated. I will try that script thanks.

Thanks that worked perfectly.

1 Like

sorry, what's the aim of this script? any live example?