File Helper - Create Array of File Names

Somehow I figured we might have access to such things. Have you mentioned host.type() previously?

EDIT: yup, right here …


The following already works, right now! :stuck_out_tongue_winking_eye:

function getFileList(path,pattern)
{
  var path = "D:/Programs/POS";
  var pattern = "*.txt";
  
  var folder = host.type("System.IO.Directory");
  var fileList = folder.GetFiles(path,pattern).ToArr();//.join();
  
  var fileCount = fileList.length;
  
  var fileArray = new Array();
  var to = "";
  
  for (var f=0; f<fileCount; f++)
  {
    var fileNameOnly = fileList[f].substr(path.length+1,fileList[f].length-path.length);
    fileArray.push(fileNameOnly);
    to += fileNameOnly + "\r\n";
  }
  
  // return path and filename
  fileList.sort;
  //return fileList;
  
  // return filename only
  fileArray.sort;
  //return fileArray;
  
  // return some test output
  return "Files matching [" + pattern + "] : " + fileCount + "\r\n" + to;
}

3 Likes