You are here

Find the last modified file in a folder using JavaScript in TestComplete

A quick script to find the lastedt modified file in a specified folder. Works really nice.

Goes thru a folder and finds the last modified file with a sertain filename
Param FolderPath String: The Path to the folder to look in
Param FilNameContains RegularExpression: The file name to match (write the regular expr // if you want to find all)
Return String with the full path to the last modified file

function FindLastModifiedFileInFolder(FolderPath,FileNameContains)
var FolderObject = aqFileSystem.GetFolderInfo(FolderPath); //The folder to look in
var FileItems = FolderObject.Files //Collection of all the files in the folder
var FileDateModified = new Array(); //Array of all the relevant date modified info for the files
var FileNumber = new Array(); //The absolute index number for the files sorted
var LatestFileNumber; //The index to the latest file modified
var NewestTime; //Placeholder for the Newest time when searching

//Builds up the arrays with the filnames containing FileNameContains reg exp
for (var i=0; i -1)

//Finds the most resent modified file
NewestTime = FileDateModified[0];
LatestFileNumber = FileNumber[0];
for (var i=0; i