How to pass path for copy command

Hi Opus Forum!
I want to copy Selected file in a newly Created folder. The Folders has been created from a Jscript Command

cmd.RunCommand('CreateFolder NAME="' + regfolder + '/' + newName + '" READAUTO');

Now I want to use Copy Command in that script

cmd.RunCommand("Copy To");

but I don't know how to write the path after Copy to
I want to add the folder which is created by newName as a path after Copy to

Hello!! Is there anyone for help me!

Which part are you having problems working out?

cmd.RunCommand('CreateFolder NAME="' + regfolder + '/' + newName + '" READAUTO');
}

This is the last line of my script. now I want to add some new line for copy selected files in to the folder which folder is created form the newName variable.
Example: I am in a folder name Label 1
After I run the JScript, 2 new folder has been created, named of that folder is Label 2\Label 3\ I use READAUTO argument so I think after run my JScript my sourcetab path will be Label 1\Label 2\Label 3\
Now I want to add cmd.RunCommand("Copy"); Line for copy some selected files into the Label 3 folder. But The file has been copied in to Label 1 Folder.
So now I have to use something code for pass the path of Label 3 folder to the Copy command. Then the selected file will copied into the Label 3 folder.

Here is my Script:

function OnClick(clickData)
{

var eSel = new Enumerator(clickData.func.sourcetab.selected);


var getfoldername = eSel.item().realpath.filepart;

var re = /\s\([0-9]+?\)\.(.*)/;
var regfolder = getfoldername.replace(re, "");

var cmd = clickData.func.command;
cmd.SetSourceTab(cmd.desttab);

	cmd.deselect = false;

	var folderName = regfolder;

	var matches = folderName.match(/^[^.]+/);
	if (matches.length != 1) { return; }

	var newName = matches[0] + ' Covers';
cmd.RunCommand('CreateFolder NAME="' + regfolder + '/' + newName + '" READAUTO');
cmd.RunCommand ('Copy');

}

That's a re-statement of the problem.

Which part are you actually having trouble working out?

Going back to your first post, if you understand both the lines you have there then the answer should be obvious. You're already passing the folder + subfolder you want to create to the CreateFolder NAME argument. You just want to do the same thing to the Copy TO argument. At least if I have understood correctly.

What I understand I can write Copy TO Command in the same statement line, so I have tried this:

cmd.RunCommand('Copy To CreateFolder NAME="' + regfolder + '/' + newName + '" READAUTO');

But It's show a error massage like this screen shot and create a folder named NAME, but it does not give any error in to the error log, So I don't understand what is my problem in here, is there any Syntax I missing?

image

The Copy command can create a destination folder, but it's done like this:

Copy HERE CREATEFOLDER="Subdir1\Subdir2"

That would create Subdir1\Subdir2 under the current folder and copy the files into it.

(The Copy command has a CREATEFOLDER argument. This is not running the CreateFolder command on the same line as the Copy command. You can't do that kind of thing. It's just a command and another command's argument that happen to have the same name.)


But the approach you had at the start would also work. You can run a command to create the folder:

CreateFolder NAME="Subdir1\Subdir2"

And then a second command to copy the files into that folder:

Copy TO="Subdir1\Subdir2"

Thanks Leo for the informative reply. you have clear me a big confusion, I had think CREATEFOLDER and CreateFolder both are same. Now I am clear CreateFolder is a command as like Copy but CREATEFOLDER is a argument, not a command.
but Steel my code doesn't copy the file, It's don't show any error also.
Here is my first command where I use CreateFolder command for Creating 2 of my Folders with this

cmd.RunCommand('CreateFolder NAME="' + regfolder + '/' + newName + '" READAUTO');

This Line works fine no problem at all.
after this line I have add This Line for copy the selected files into the 2nd folder which is created from newName variable. But It's doesn't work.

cmd.RunCommand('Copy TO="' + regfolder + '/' + newName + '"');

I have 1 more problem. I have to copy the first file in to folder 1 which is created by regfolder variable. in the Standard function I was used @firstfileonly for mark up the first file, How to mark up the first file only in the JScript?

If any one wants to try here is my total code:

function OnClick(clickData)
{
	var eSel = new Enumerator(clickData.func.sourcetab.selected);
	var getfoldername = eSel.item().realpath.filepart;
	var re = /\s\([0-9]+?\)\.(.*)/;
	var regfolder = getfoldername.replace(re, "");
	var cmd = clickData.func.command;
	
cmd.SetSourceTab(cmd.desttab);
cmd.RunCommand('Set Focus=Toggle');

cmd.ClearFiles();
cmd.deselect = false;

	var cmd = clickData.func.command;
	var folderName = regfolder;
	var matches = folderName.match(/^[^.]+/);
	if (matches.length != 1) { return; }
	var newName = matches[0] + ' Covers';
	cmd.RunCommand('CreateFolder NAME="' + regfolder + '/' + newName + '" READAUTO');
    cmd.RunCommand('Copy TO="' + regfolder + '/' + newName + '"');
}

What happens? What is the error message?

One problem at a time, please. Or start a new thread for it.

When I run the script the two folder will create and read auto will work, after that nothing happened, no error log, but the copy to command does not work also.

You cleared the files, there's nothing to copy.

cmd.ClearFiles();
1 Like

Ok Now I had tried without

cmd.ClearFiles();

Now Files Copied to the Label 1 Folder, But I want to copy to into the Label 2\Label 3 Folder.
Is there any mistake in this line?

cmd.RunCommand('Copy TO="' + regfolder + '/' + newName + '"');

Hi My Dear Leo!
Can you tell me what is wrong in this code? Why does the Copy TO command paste the file into Label 3 Folder?
I already delete this line from the code cmd.ClearFiles(); but steel it's not worked

Sorry, I don't have time to help you every five minutes. I suggest breaking the problem down into something more simple, and trying to understand the building blocks you are using, instead of just putting them together and then asking us to do everything for you when they don't quite work.