Looking to sort jobs containing folders...

Post Reply
Danny
Member
Posts: 27
Joined: Wed Dec 08, 2010 5:59 pm

Looking to sort jobs containing folders...

Post 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
dkelly
TOP CONTRIBUTOR
Posts: 628
Joined: Mon Nov 29, 2010 8:45 pm
Location: Alpharetta GA USA
Contact:

Looking to sort jobs containing folders...

Post by dkelly »

In script you'd use job.isFile() or job.isFolder()



You can also use Switch variables [Job.IsFile] and [Job.IsFolder]
tz8
Member
Posts: 84
Joined: Mon Aug 13, 2012 12:56 pm

Looking to sort jobs containing folders...

Post 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
Danny
Member
Posts: 27
Joined: Wed Dec 08, 2010 5:59 pm

Looking to sort jobs containing folders...

Post by Danny »

Nice!



It works great tz8, thanks for your help.
Post Reply