Forum Discussion
- gunnettmdContributor
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();
} - ArmandsBrunsFrequent ContributorHi Mike
Thanks for your support
I tried to convert VBScript :)
but it shows me error:
-----------------------------------------------------
Function findLatestFileAndLaunch()
filePath = "D:\"
fileExtension = "Result_IE_*.xlsx"
i = 0
Set filesInFolder = Array()
Set fileInformation = Array()
Dim 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
Set fileInformation(i) = filesInFolder.Next
i = i + 1
'Set newestFile to the first file that was found
newestFile = fileInformation(0)
For a = 0 To fileInformation.length-1
'Compare the files and find the most recent.
if (aqDateTime.Compare(newestFile.DateLastModified, fileInformation(a).DateLastModified) = 1) Then
newestFile = fileInformation(a)
End If
Next
'Add the latest file as a TestedApp and Run it.
Set appIdx = TestedApps.Add(newestFile.Path)
TestedApps.Items(appIdx).Run()
End Function
-----------------------------------------------------
Armands - irina_lukinaSuper Contributor
Hi Armands,
Some time ago, I created a similar script for one of our users. Please refer to the following forum thread and check the latest code snippet:
http://community.smartbear.com/forum/post/?mode=singleThread&thread=d44c2a9c-1426-4199-8a55-8e19404c9228As for your script, as far as I can see, you've missed the WEnd operation:
while filesInFolder.HasNext
Set fileInformation(i) = filesInFolder.Next
i = i + 1
wend ' <- Right hereI hope this helps :)
- ArmandsBrunsFrequent ContributorHi Irina,
Thank you for your support ;)
BR.
Armands