The below code will read files from a directory into an array, then sort the array.
// Read a directory, list the files, and rearrange the array
// so the files are in ascending order by modified date
// Use LASTMODIFIED_REVERSE to reverse the order
// Get the source directory
var srcDirectory = new java.io.File("C:\\HL7\\In");
// Create a list of files in an array
var listFiles = srcDirectory.listFiles();
// Sort the array
java.util.Arrays.sort(listFiles, org.apache.commons.io.comparator.LastModifiedFileComparator.LASTMODIFIED_COMPARATOR);
// List the files in the array
for (var i = 0; i < listFiles.length; i++) {
qie.debug(listFiles[i].getName());
}