How do I get a list of files in a directory and sort them by modified date?

0 votes
asked Jan 7 by jon-t-7005 (2,090 points)

1 Answer

0 votes

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"C:\\HL7\\In");

// Create a list of files in an array
var listFiles = srcDirectory.listFiles();

// Sort the array

// List the files in the array
for (var i = 0; i < listFiles.length; i++) {

answered Jan 7 by jon-t-7005 (2,090 points)