Read result of folder listing process in script

Is there a way to access the XML result from a folder listing within a script without having to output to file and then read back in?

Not quite sure what you mean: the output of the Folder Listing task is an XML file. So you can read it with the standard XML functionality in Workflow, or you can access it as a whole using the %c system variable.

Hi Phil.

So I’ve got a folder listing then a script straight after where I need to do various things. So at the moment I’ve added a “Send to Folder” after the folder listing and then read it in the script. However just to be neater I would like to cut out the Send to Folder and just access the file using Watch.GetVariable(“???”) if that makes sense

Well you can access the Folder Listing’s output through the Watch.GetJobFileName() method.

If you want to parse that file as XML, use the MSXML library. For instance, this script uses the current job file and lists all file paths and names from a folder listing output :

var xmlDoc = new ActiveXObject("Msxml2.DOMDocument.3.0");
xmlDoc.async = false;
xmlDoc.load(Watch.GetJobFileName());

if(!xmlDoc.parseError.errorCode) {
  xmlDoc.setProperty("SelectionLanguage", "XPath");
  var files = xmlDoc.selectNodes("//file");
  for(var i=0;i<files.length;i++){
    Watch.log(files[i].selectSingleNode("path").text + files[i].selectSingleNode("filename").text,2)
  }
} else {
  Watch.log("Error parsing XML",1);
}

Insert that script immediately after your Folder Listing task to see the list of files in the Messages pane.