How to Validate recently downloaded output Excel Files
- 3 years ago
Hi edgarh88, @
To expand upon Emma's (ebarbera) suggestion, you could get the most recently created file from a directory. This function will allow you to pass in the directory and file extension and will return the most recent created file path. I added a test function below to show how to pass in your parameters. I hope this helps.
function getMostRecentCreatedFile(directoryPath, searchPattern)
{
var newestFilePath = "";
var previousCreationTime = "1/1/1900";
try
{
var files = aqFileSystem.FindFiles(directoryPath, searchPattern, false);
if (files != null)
{
while(files.HasNext())
{
var file = files.Next();
var creationTime = aqFile.GetCreationTime(file.Path);
if (aqDateTime.Compare(creationTime, previousCreationTime) == 1)
{
previousCreationTime = creationTime;
newestFilePath = file.Path;
}
}
}
}
catch(e)
{
Log.Error("Exception in getMostRecentCreatedFile", e.descrpition);
}
//
return newestFilePath;
}
function testGetFile()
{
var filePath = getMostRecentCreatedFile("C:\\Users\\herrerae\\Downloads", "*.xlsx");
}