Micro Focus QTP (UFT) Forums
To find the latest file - Printable Version

+- Micro Focus QTP (UFT) Forums (https://www.learnqtp.com/forums)
+-- Forum: Micro Focus UFT (earlier known as QTP) (https://www.learnqtp.com/forums/Forum-Micro-Focus-UFT-earlier-known-as-QTP)
+--- Forum: VB Scripting/Descriptive Programming (https://www.learnqtp.com/forums/Forum-VB-Scripting-Descriptive-Programming)
+--- Thread: To find the latest file (/Thread-To-find-the-latest-file)



To find the latest file - mrajeshtnl - 02-27-2012

How can we write a script to find a latest file in a folder

Thanks


RE: To find the latest file - inborntester - 02-27-2012

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)