check via file.exists with wildcard

Post Reply
cristalica
Newbie
Posts: 8
Joined: Sun Dec 28, 2014 8:03 pm

check via file.exists with wildcard

Post by cristalica »

Hi there,

I'm looking for a solution to check for a file in a specific folder, the file has a prefix PRD_ which is always the same but the filename itself changes with every job.
Currently I check only if the folder exist, if not a sync process starts but sometimes the PRD_ file is missing. I have to make sure that the PRD_xxx file inside that folder exists before the workflow continues.


The current script is this:

Code: Select all

function findConnectionByName( s : Switch, inName : String ) : Connection
{
    var outConnectionList = s.getOutConnections();
    for (i=0; i < outConnectionList.length; i++) {
        var theConnection = outConnectionList.getItem(i);
        var theName = theConnection.getName();
        if (inName == theName)
            return theConnection;
    }
    return null;
}

function jobArrived( s : Switch, job : Job )
{
	var JobTicketID = job.getVariableAsString('[Metadata.Text:Path="/STÜCKLISTE/KOPF/CONFID",Dataset="meineKonfigID",Model="XML"]');
	var TicketPathVIP = "//cs-switch/Bilddaten-VIP/"+JobTicketID;
	var theConnectionName = "BASISDATENHOLEN";
  
		if (File.exists(TicketPathVIP)) {
	 	theConnectionName = "BASISDATENOK";
  		}
  
  if (theConnectionName.length) {
        var theConnection = findConnectionByName(s, theConnectionName);
        if (theConnection != null) {
            job.sendTo( theConnection, job.getPath() );
        } else {
            job.fail( "Unable to find connection named '"+theConnectionName+"'");
        }
}
}

function timerFired( s : Switch )
{
}
What can I do in order to make the script check for a file like

var TicketPathVIP = "//cs-switch/Bilddaten-VIP/"+JobTicketID+"/PRD_*";

thanks for any hint,

Daniel
bens
Member
Posts: 130
Joined: Thu Mar 03, 2011 10:13 am

Re: check via file.exists with wildcard

Post by bens »

Have a look at the entryList function of the Dir class. It will give the contents of a folder on disk, with filtering.
User avatar
gabrielp
Advanced member
Posts: 577
Joined: Fri Aug 08, 2014 4:31 pm
Location: Boston
Contact:

Re: check via file.exists with wildcard

Post by gabrielp »

For a non-scripting solution, you might be able to inject on that folder with a wildcard. If the inject fails, you could determine that the PRD_ file is not there. Also, I would remove the timerFired function if you're not using it in this script.

I think bens has the best solution. What you're looking for will be related to the Dir class in Scripter. If you can't get filtering working, I'm sure you could get the contents of the folder as an array then loop through them, checking for the first 4 characters of each file name.
Chat: open-automation @ gitter
Code: open-automation & dominickp @ GitHub
Tools: Switch, Pitstop, EPMS, Veracore, PageDNA, SmartStream, Metrix
Post Reply