Micro Focus QTP (UFT) Forums

Full Version: To find the latest file
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
How can we write a script to find a latest file in a folder

Thanks
Based on modified date of files we can get, means the file one having latest modified date is the latest file.

Code:
Set FSO = CreateObject("Scripting.FileSystemObject")
Set Folder = FSO.GetFolder("D:\test")
LatestModifiedFileDate = #1/1/0001#
For Each File In Folder.Files
    If  File.DateLastModified > LatestModifiedFileDate Then
        LatestModilfiedFile= File.Name
        LatestModifiedFileDate = File.DateLastModified
    End If
Next
msgbox (LatestModilfiedFile)