Grab Directories from Folder after they are unchanged for a certain time

Post Reply
sascha.koerber
Newbie
Posts: 10
Joined: Mon Mar 19, 2012 6:34 pm

Grab Directories from Folder after they are unchanged for a certain time

Post by sascha.koerber »

Hi there Switch Users,



we're using PowerSwitch 10. We want to create a workflow, that grab folders from a directory. The folder gets filled with files manually, so it would be great if the flow would check, if the folder was not touched for a certain time.



Like this:



- User creates a Folder "myFolder"

- User adds files to Folder "myFolder" manually

- Switch waits till "myFolder" wasnt touched for like 5 mins

- Switch processes "myFolder" (transfer, copy whatever)



I know there is a parameter in the settings that can do this, but this parameter impacts all flows.



Do you have an idea how i could achieve this without changing the parameter in the settings? Any Ideas?



Thanks a lot!



Sascha
sascha.koerber
Newbie
Posts: 10
Joined: Mon Mar 19, 2012 6:34 pm

Grab Directories from Folder after they are unchanged for a certain time

Post by sascha.koerber »

Addition:



I've tried using the "Hold Job" function but that did not work out. The function is able to delay the folder transfer for a certain time, BUT Switch adds the Job Ticket Name to the Folder Name as soon as the folder gets scanned. So the folder with is not visible to the user filling it anymore under its previous name.



Any other Ideas how to check that the folder was not changed for a certain time before it is transfered. Maybe a little script or something?
dkelly
TOP CONTRIBUTOR
Posts: 658
Joined: Mon Nov 29, 2010 8:45 pm
Location: Alpharetta GA USA
Contact:

Grab Directories from Folder after they are unchanged for a certain time

Post by dkelly »

I can think of 3 ways this could be implemented.



1) Set the scan time for the input folder to 300 secs (5 mins) and the stable time in Prefs to something like 60 secs. This would have minimal impact on other flows but prevent this particular job from being picked up early.



2) Use a Submit Hierarchy element with a custom script for determining which folders to include or exclude dynamically.



3) Write a custom script to replace the input folder element that performs all of the monitoring logic itself.



Dwight Kelly

Apago, Inc.

dkelly@apago.com
sascha.koerber
Newbie
Posts: 10
Joined: Mon Mar 19, 2012 6:34 pm

Grab Directories from Folder after they are unchanged for a certain time

Post by sascha.koerber »

Ahhh! Good hints!



I think i will stick with option 3 and write a small batch script to monitor the change-date of the folders and just move them to my PowerSwitch input folder afterwards. Sound like the easiest way for a workaround.



Thanks, Dwight (again)!
dkelly
TOP CONTRIBUTOR
Posts: 658
Joined: Mon Nov 29, 2010 8:45 pm
Location: Alpharetta GA USA
Contact:

Grab Directories from Folder after they are unchanged for a certain time

Post by dkelly »

If you have the Scripting module, you could write the monitoring script directly in Switch.
mwinker
Member
Posts: 37
Joined: Wed Dec 22, 2010 2:36 am

Grab Directories from Folder after they are unchanged for a certain time

Post by mwinker »

I'm trying to set up something on the lines of this, where after a set period of maybe 2 months, files will be automatically pulled from the folder at the end of a flow (where the unique name has been removed) and sent to the recycle. I have been doing this with an Apple Automator action triggered once a day Monday through Friday from iCal. That works OK but I was wondering if there was an easy way to do it in Switch without introducing a new unique name on files in that folder. It sort of looks like this might be accomplished with inject job except that it looks like I'd need to have the actual file name instead of something like a modification date.

I also looked at Submit Hierarchy but it looks like that's set up to process folders rather than just PDF files.

Nobody here has a decent grip on scripting or "scripting as it relates to Switch". Can anyone recommend how one might pursue some scripting training as it would relate to something like switch. While I could probably find classes in javascript around, they tend to be for web production and I question whether learning that is applicable.



Mike
jonasy
Member
Posts: 30
Joined: Tue Feb 01, 2011 11:50 am

Grab Directories from Folder after they are unchanged for a certain time

Post by jonasy »

Hi Mike,



Switch uses the unique prefix to link the job to the internal metadata. It is added just before processing and removed after processing. The creation of the prefix can't be avoided when using Switch tools, however it should not cause problems because it is removed again after processing.



Some resellers provide Switch training including scripting. You might check if your reseller provides this service.



Kind regards,

Jonas
dkelly
TOP CONTRIBUTOR
Posts: 658
Joined: Mon Nov 29, 2010 8:45 pm
Location: Alpharetta GA USA
Contact:

Grab Directories from Folder after they are unchanged for a certain time

Post by dkelly »

mwinker wrote: Nobody here has a decent grip on scripting or "scripting as it relates to Switch". Can anyone recommend how one might pursue some scripting training as it would relate to something like switch.


Hello, I'm teaching a full day class on Switch Javascript during Graph Expo. See http://bpt.me/264833 for more information.



Dwight Kelly

Apago, Inc.
dkelly
TOP CONTRIBUTOR
Posts: 658
Joined: Mon Nov 29, 2010 8:45 pm
Location: Alpharetta GA USA
Contact:

Grab Directories from Folder after they are unchanged for a certain time

Post by dkelly »

The solution I created involves a custom script that Switch calls once a day. There are 2 parameters for the script, the directory to watch and the number of days since a subdirectory has been modified before it is processed.



Here the script deletes directories that are over 30 days old.







I can't connect the Archive Hierarchy element directly to the script since it doesn't allow output connections. However, a single Flow can contain both parts.



Dwight Kelly

Apago, Inc.

dkelly@apago.com
dkelly
TOP CONTRIBUTOR
Posts: 658
Joined: Mon Nov 29, 2010 8:45 pm
Location: Alpharetta GA USA
Contact:

Grab Directories from Folder after they are unchanged for a certain time

Post by dkelly »

Here's the code for the script.



// waitForStableDirectory

// Written by Dwight Kelly <dkelly@apago.com>

// Copyright 2012, All rights reserved

// Date: 08/14/12



// Switch logging & output levels

const cLogInfo = 1;

const cLogError = 3;



const secsInADay = 86400;



function timerFired( s : Switch )

{

var dirName = s.getPropertyValue("directory");

var stableDays = s.getPropertyValue("stableDays")*secsInADay;



s.setTimerInterval(secsInADay); // run script once every 24-hours



var dirFile = new File(dirName);

if (dirFile.exists) {

var now = new Date();

var theDir = new Dir( dirName );

var theFilesList = theDir.entryList( "*", Dir.Dirs );

for( var index = 0; index < theFilesList.length; index++ ) {

var theFile = theFilesList[ index ];

if (theFile == "." || theFile == "..")

continue;

var thePath = dirName + "/" + theFile;

var pathFile = new File(thePath);

if (pathFile.lastModified.getTime()+stableDays < now.getTime()) {



var j = s.createNewJob("waitForStableDirectory");

j.sendToSingle(thePath, theFile);

}

}

} else {

s.log(cLogError, "Error: directory " + dirName + " doesn't exist");

}

}
mwinker
Member
Posts: 37
Joined: Wed Dec 22, 2010 2:36 am

Grab Directories from Folder after they are unchanged for a certain time

Post by mwinker »

Thanks for the good info All. I was away for a week of much needed vacation. It may be a few days before I can try this out. I forwarded the info on the class to our superior to eschew.



Mike
Post Reply