Page 1 of 1

External File Copy using Javascript

Posted: Tue Feb 11, 2020 11:55 pm
by kheslin
I'm working on a script to move an external file from one directory to another.
I can't seem to get it to work. I've reduced the script to this and still no luck.

function jobArrived( s : Switch, job : Job )
{
var SourceFile = "//SPCV02/testing/FromFolder/FileToMove.txt";
var DestinationFile = "//SPCV02/testing/ToFolder/FileToMove.txt";

s.copy( SourceFile , DestinationFile );


// And move the job to the single output connection
job.sendToSingle( job.getPath() );

}

Re: External File Copy using Javascript

Posted: Wed Feb 12, 2020 8:36 am
by freddyp
It is good practice to make sure the separators are correct for your operating system:

Code: Select all

var sourceFile = File.toNativeSeparators("//SPVC02/etc.");
This being said, why use a script? By the looks of it, what you are doing is that an incoming job triggers the copying of a file from one location to another. You can also accomplish that by using "Inject job" (note that the interesting properties are on the outgoing connection) to get FileToMove.txt into the flow and where you drop it afterwards is a matter of having an output folder with the desired path.

Re: External File Copy using Javascript

Posted: Wed Feb 12, 2020 7:05 pm
by kheslin
I was using a script because I didn't know that "Inject Job" could do this.

I'm off to try it out

Thanks