External File Copy using Javascript

Post Reply
kheslin
Newbie
Posts: 4
Joined: Tue Jun 27, 2017 11:37 pm

External File Copy using Javascript

Post by kheslin » Tue Feb 11, 2020 11:55 pm

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() );

}

freddyp
Advanced member
Posts: 479
Joined: Thu Feb 09, 2012 3:53 pm

Re: External File Copy using Javascript

Post by freddyp » Wed Feb 12, 2020 8:36 am

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.

kheslin
Newbie
Posts: 4
Joined: Tue Jun 27, 2017 11:37 pm

Re: External File Copy using Javascript

Post by kheslin » Wed Feb 12, 2020 7:05 pm

I was using a script because I didn't know that "Inject Job" could do this.

I'm off to try it out

Thanks

Post Reply