Folder Listing Folder as File Mask

Hi there,

Is it possible to include a folder path in the file mask?

I need to look only in folders that start with “PROOFS_” and there may be subfolders in these folders

I’ve tried PROOFS_**.pdf & PROOFS_\\.pdf but I’m not getting any hits.

Or am I going to have to folder list the root dir and filter the file list ? I wanted to avoid this as there are a lot of folders & files in this directory and it’s taking 10 minutes to get the list back.

The folder listing task is not that fine-grained. Masks are only applied to file names, not to folder names.

I had an old recursive script that I adapted according to your specs, you could try that:

var rootName = "L:\TestOutput";
var subFolderRegEx = /proofs_.*/i;
var fileRegEx = /.*\.csv/i;
var result = [];

var fso = new ActiveXObject("Scripting.FileSystemObject");
var folder = fso.GetFolder(rootName);
var e = new Enumerator(folder.SubFolders);
for (;!e.atEnd(); e.moveNext()) {
  if(subFolderRegEx.test(e.item().Name)){
    getFiles(e.item());
  }
}

// write the list of files to the current job file
var jobFile = fso.CreateTextFile(Watch.GetJobFileName());
result.forEach(function(e){
  jobFile.writeLine(e);
});
jobFile.Close();


function getFiles(fld) {
  // first, get all matching files from subfolder
  var f = new Enumerator(fld.files);
  for (;!f.atEnd(); f.moveNext()) {
    if(fileRegEx.test(f.item().Name)){
      result.push(fld.path + "\\" + f.item().Name);
    }
  }

  // now recurse through subfolders
  var e = new Enumerator(fld.SubFolders);
  for (;!e.atEnd(); e.moveNext()) {
    getFiles(e.item());
  }

}

Change the rootName variable on the first line to the actual name of the root folder in which the proof_* subfolders are located. The script will replace the current job file with a list of individual file path and names, one on each line. You could then process that file with a standard splitter.

Start your process with a Create File task, and then insert that script immediately after.

1 Like

Hi Phil,

Thanks for this, it’s exactly what I needed.

Michael