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...
-
- TOP CONTRIBUTOR
- Posts: 628
- Joined: Mon Nov 29, 2010 8:45 pm
- Location: Alpharetta GA USA
- Contact:
Looking to sort jobs containing folders...
In script you'd use job.isFile() or job.isFolder()
You can also use Switch variables [Job.IsFile] and [Job.IsFolder]
You can also use Switch variables [Job.IsFile] and [Job.IsFolder]
Looking to sort jobs containing folders...
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
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...
Nice!
It works great tz8, thanks for your help.
It works great tz8, thanks for your help.