Page 1 of 1

Looking to sort jobs containing folders...

Posted: Tue Apr 01, 2014 9:25 pm
by Danny
Hello,

I'm setting up a flow where I need to check if a job folder going through a flow contains a folder(or folders). If it does contain a folder, I'd like it to go to an outgoing connection and if it doesn't I'd like it to go to a different outgoing connection.



Is this possible with Switch scripting?



Thanks for your help,



Danny

Looking to sort jobs containing folders...

Posted: Tue Apr 01, 2014 10:51 pm
by dkelly
In script you'd use job.isFile() or job.isFolder()



You can also use Switch variables [Job.IsFile] and [Job.IsFolder]

Looking to sort jobs containing folders...

Posted: Thu Apr 03, 2014 11:36 am
by tz8
first:



create a script where connection type is "Filter" (include/exclude folder set to No).



then you can use this script:





function jobArrived( s : Switch, job : Job )

{

var jobDir = new Dir( job.getPath() );

var jobFolderList = jobDir.entryList( "*", Dir.Dirs|Dir.NoDotAndDotDot );

if( jobFolderList.length > 0 )

{

job.log( 1, "Job " + job.getName() + " contains " + jobFolderList.length + " folder(s)" );

// the job folder contains folders

// do stuff with it

job.setPrivateData( "folders", "true" )

job.sendToFilter( job.getPath(), job.getName() + "_withFolders" );

}

else

{

job.log( 1, "Job " + job.getName() + " contains no folders" );

// job folder does not contain folders

// do stuff with it

job.setPrivateData( "folders", "false" );

job.sendToFilter( job.getPath(), job.getName() + "_noFolders" );

}

}



on the outgoing connections apply a file pattern in "include these files" with "*_withFolders" or "*_noFolders"



that should do it

Looking to sort jobs containing folders...

Posted: Thu Apr 03, 2014 5:38 pm
by Danny
Nice!



It works great tz8, thanks for your help.