File Directory in Javascript
Posted: Thu Mar 20, 2014 8:33 pm
So I have been working on a script that will pull old job folders from several directories based on the job number passed from switch. Everything is working great, but I ran into a snag. Some of the folders are named with a "_Customer Name" and some are not. The script works as is should for the folders WITHOUT the "_customer Name" but fails to retrieve the folders WITH "_Customer Name".
What I Assume I should do is get a directory of each path (var locObj[] ) then do a match against my job Number. but, i can not for the life of me figure out how to get a directory out of javascript.
Or, Am i over thinking it?
Attached is the current script
// Is invoked each time a new job arrives in one of the input folders for the flow element.
// The newly arrived job is passed as the second parameter.
function jobArrived( s : Switch, job : Job )
{
//Total Number of Locations//
var NumberOfLocations = 22;
//Location Paths//
var LocObj = [];
LocObj['Location1']= "/Volumes/prep_files/Jobs/";
LocObj['Location2']= "/Volumes/prepress_files/Archived Jobs/• Xitron_Backups/";
LocObj['Location3']= "/Volumes/prepress_files/Archived Jobs/• Prinergy_Backups/1016001 - 1017000/";
LocObj['Location4']= "/Volumes/prepress_files/Archived Jobs/• Prinergy_Backups/1015001 - 1016000/";
LocObj['Location5']= "/Volumes/prepress_files/Archived Jobs/• Prinergy_Backups/1014001 - 1015000/";
LocObj['Location6']= "/Volumes/prepress_files/Archived Jobs/• Prinergy_Backups/1013001 - 1014000/";
LocObj['Location7']= "/Volumes/prepress_files/Archived Jobs/• Prinergy_Backups/1012001 - 1013000/";
LocObj['Location8']= "/Volumes/prepress_files/Archived Jobs/• Prinergy_Backups/1011001 - 1012000/";
LocObj['Location9']= "/Volumes/prepress_files/Archived Jobs/• Prinergy_Backups/1010001 - 1011000/";
LocObj['Location10']= "/Volumes/prepress_files/Archived Jobs/• Prinergy_Backups/1009001 - 1010000/";
LocObj['Location11']= "/Volumes/prepress_files/Archived Jobs/• Prinergy_Backups/1008001 - 1009000/";
LocObj['Location12']= "/Volumes/prepress_files/Archived Jobs/• Prinergy_Backups/1007001 - 1008000/";
LocObj['Location13']= "/Volumes/prepress_files/Archived Jobs/• Prinergy_Backups/1006001 - 1007000/";
LocObj['Location14']= "/Volumes/prepress_files/Archived Jobs/• Prinergy_Backups/1005001 - 1006000/";
LocObj['Location15']= "/Volumes/prepress_files/Archived Jobs/• Prinergy_Backups/1004001 - 1005000/";
LocObj['Location16']= "/Volumes/prepress_files/Archived Jobs/• Prinergy_Backups/1003001 - 1004000/";
LocObj['Location17']= "/Volumes/prepress_files/Archived Jobs/• Prinergy_Backups/1002001 - 1003000/";
LocObj['Location18']= "/Volumes/prepress_files/Archived Jobs/• Prinergy_Backups/1001001 - 1002000/";
LocObj['Location19']= "/Volumes/prepress_files/Archived Jobs/• Prinergy_Backups/1000000 - 1001000/";
LocObj['Location20']= "/Volumes/prepress_files/Archived Jobs/• Prinergy_Backups/500000 (Online Orders)/";
LocObj['Location21']= "/Volumes/prepress_files/DONTUSE/"
LocObj['Location22']= "/Volumes/prepress_files/Transfer/• Prepress/Prepress_Files_Programs/Switch Backup/NoJob";
// Switch metadata with history number//
var JobNumber = job.getVariableAsString('[Metadata.Text:Path="/field-list/field[2]/field-list/field/value",Dataset="Submit",Model="XML"]');
//I have no Idea what this is its from fred//
var theSourcePath = job.createPathWithName( JobNumber );
//Counter for loop//
var Counter = 1;
// location path test: True=nofile False=FileFound
var Empty = "True";
//Loop and search locations for history number//
while(Empty == "True")
{
var shortcut = LocObj['Location'+Counter+'']
//var path = Location1+Counter;
var folderName = shortcut+JobNumber;
s.log(1,folderName);
if (File.exists(folderName))
{
Empty = "False";
s.copy( folderName, theSourcePath );
job.sendToSingle( theSourcePath );
job.sendToNull( job.getPath() );
s.log(1,JobNumber);
}
//Break loop is no files are found//
else if(Counter == NumberOfLocations)
{
var theSourcePath = job.createPathWithName( "NoJob" );
var folderName = shortcut;
s.copy( folderName, theSourcePath );
job.sendToSingle( theSourcePath );
job.sendToNull( job.getPath() );
s.log(1,"Folder " + folderName + " does not exist");
Empty = "False";
}
else
{
Counter++;
}
}
}
What I Assume I should do is get a directory of each path (var locObj[] ) then do a match against my job Number. but, i can not for the life of me figure out how to get a directory out of javascript.
Or, Am i over thinking it?
Attached is the current script
// Is invoked each time a new job arrives in one of the input folders for the flow element.
// The newly arrived job is passed as the second parameter.
function jobArrived( s : Switch, job : Job )
{
//Total Number of Locations//
var NumberOfLocations = 22;
//Location Paths//
var LocObj = [];
LocObj['Location1']= "/Volumes/prep_files/Jobs/";
LocObj['Location2']= "/Volumes/prepress_files/Archived Jobs/• Xitron_Backups/";
LocObj['Location3']= "/Volumes/prepress_files/Archived Jobs/• Prinergy_Backups/1016001 - 1017000/";
LocObj['Location4']= "/Volumes/prepress_files/Archived Jobs/• Prinergy_Backups/1015001 - 1016000/";
LocObj['Location5']= "/Volumes/prepress_files/Archived Jobs/• Prinergy_Backups/1014001 - 1015000/";
LocObj['Location6']= "/Volumes/prepress_files/Archived Jobs/• Prinergy_Backups/1013001 - 1014000/";
LocObj['Location7']= "/Volumes/prepress_files/Archived Jobs/• Prinergy_Backups/1012001 - 1013000/";
LocObj['Location8']= "/Volumes/prepress_files/Archived Jobs/• Prinergy_Backups/1011001 - 1012000/";
LocObj['Location9']= "/Volumes/prepress_files/Archived Jobs/• Prinergy_Backups/1010001 - 1011000/";
LocObj['Location10']= "/Volumes/prepress_files/Archived Jobs/• Prinergy_Backups/1009001 - 1010000/";
LocObj['Location11']= "/Volumes/prepress_files/Archived Jobs/• Prinergy_Backups/1008001 - 1009000/";
LocObj['Location12']= "/Volumes/prepress_files/Archived Jobs/• Prinergy_Backups/1007001 - 1008000/";
LocObj['Location13']= "/Volumes/prepress_files/Archived Jobs/• Prinergy_Backups/1006001 - 1007000/";
LocObj['Location14']= "/Volumes/prepress_files/Archived Jobs/• Prinergy_Backups/1005001 - 1006000/";
LocObj['Location15']= "/Volumes/prepress_files/Archived Jobs/• Prinergy_Backups/1004001 - 1005000/";
LocObj['Location16']= "/Volumes/prepress_files/Archived Jobs/• Prinergy_Backups/1003001 - 1004000/";
LocObj['Location17']= "/Volumes/prepress_files/Archived Jobs/• Prinergy_Backups/1002001 - 1003000/";
LocObj['Location18']= "/Volumes/prepress_files/Archived Jobs/• Prinergy_Backups/1001001 - 1002000/";
LocObj['Location19']= "/Volumes/prepress_files/Archived Jobs/• Prinergy_Backups/1000000 - 1001000/";
LocObj['Location20']= "/Volumes/prepress_files/Archived Jobs/• Prinergy_Backups/500000 (Online Orders)/";
LocObj['Location21']= "/Volumes/prepress_files/DONTUSE/"
LocObj['Location22']= "/Volumes/prepress_files/Transfer/• Prepress/Prepress_Files_Programs/Switch Backup/NoJob";
// Switch metadata with history number//
var JobNumber = job.getVariableAsString('[Metadata.Text:Path="/field-list/field[2]/field-list/field/value",Dataset="Submit",Model="XML"]');
//I have no Idea what this is its from fred//
var theSourcePath = job.createPathWithName( JobNumber );
//Counter for loop//
var Counter = 1;
// location path test: True=nofile False=FileFound
var Empty = "True";
//Loop and search locations for history number//
while(Empty == "True")
{
var shortcut = LocObj['Location'+Counter+'']
//var path = Location1+Counter;
var folderName = shortcut+JobNumber;
s.log(1,folderName);
if (File.exists(folderName))
{
Empty = "False";
s.copy( folderName, theSourcePath );
job.sendToSingle( theSourcePath );
job.sendToNull( job.getPath() );
s.log(1,JobNumber);
}
//Break loop is no files are found//
else if(Counter == NumberOfLocations)
{
var theSourcePath = job.createPathWithName( "NoJob" );
var folderName = shortcut;
s.copy( folderName, theSourcePath );
job.sendToSingle( theSourcePath );
job.sendToNull( job.getPath() );
s.log(1,"Folder " + folderName + " does not exist");
Empty = "False";
}
else
{
Counter++;
}
}
}