Page 1 of 1

check via file.exists with wildcard

Posted: Wed Apr 06, 2016 9:57 am
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

Re: check via file.exists with wildcard

Posted: Wed Apr 06, 2016 1:51 pm
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.

Re: check via file.exists with wildcard

Posted: Wed Apr 06, 2016 4:43 pm
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.