Below is the script:
Code: Select all
function jobArrived( s : Switch, job : Job ) {
var debugLevel = s.getPropertyValue( "debugLevel" );
// create the file handler
var fileList = new File(job.getPath());
// open the file for reading
fileList.open(File.ReadOnly);
// read each line into an array
var lines = fileList.readLines();
var theSourcePath;
for(i = 0; i < lines.length; i++) {
sourcePath = lines[i];
// don't process blank lines
if (sourcePath == '') {
continue;
}
// create a file handle for the file to be moved
sourceFile = new File(sourcePath);
if (!File.exists(sourcePath)) {
s.log(3, sourcePath + " does not exist");
continue;
}
// get the name of the file (without the path information)
fileName = sourceFile.name;
// create a new job using the name of the file to copy
newJob = s.createNewJob(fileName);
jobPath = newJob.createPathWithName(fileName, true);
// copy the file to the new job.
s.copy( sourcePath, jobPath );
if(debugLevel == 1){
s.log(2, "Copy " + sourcePath + " to job");
}
// trim hierarchy segments
var jobPathArray = sourcePath.split("/");
jobPathArray.splice(0, s.getPropertyValue("Trim_Hierarchy"));
jobPathArray.shift();
jobPathArray.pop();
// set hierarchy information
newJob.setHierarchyPath(jobPathArray);
// send the file along to a single connection
newJob.sendToSingle( jobPath );
if(debugLevel == 1){
s.log(2, "Send to single: " + jobPath);
}
}
if(debugLevel == 1){
s.log(2, "Done processing");
}
// cleanup
job.sendToNull( job.getPath() );
fileList.close();
}