Forum Discussion
Hi Armands Bruns,
This function is something I wrote that could be used for what you are looking to do. It searches on the DateLastModified attribute but that can be changed to DateCreated or DateLastAccessed as well.
Note that it is written in JScript.
function findLatestFileAndLaunch()
{
var filePath = "C:\\";
var fileExtension = "*.exe";
var i = 0;
var filesInFolder = new Array();
var fileInformation = new Array();
var newestFile;
//Grab the files that match the extension supplied from the folder specified.
filesInFolder = aqFileSystem.FindFiles(filePath, fileExtension);
//Grab the file details for comparison.
while (filesInFolder.HasNext())
{
fileInformation = filesInFolder.Next();
i++;
}
//Set newestFile to the first file that was found.
newestFile = fileInformation[0];
for (var a = 0; a < fileInformation.length; a++)
{
//Compare the files and find the most recent.
if (aqDateTime.Compare(newestFile.DateLastModified, fileInformation.DateLastModified) == 1)
newestFile = fileInformation;
}
//Add the latest file as a TestedApp and Run it.
var appIdx = TestedApps.Add(newestFile.Path);
TestedApps.Items(appIdx).Run();
}