How to find last modified file (TestComplete, QTP, VBScript)
Reference page: Service Functions – System (QTP, VBScript)
Description
Check folder exists – check folder has files. Iterate through collection of files and keep reference of the most recently modified file (its DateLastModified property is always the highest number). The remaining reference is the one that you need. In case of errors the function returns Nothing.
Note. In some cases, you may want to use DateCreated or DateLastAccessed properties.
Implementation
Public Function GetLastModifiedFile(ByVal sFolderPath)
Dim FSO, objFolder, objFile
Dim objFileResult, longDateTime
Dim boolRC
Set FSO = CreateObject("Scripting.FileSystemObject")
boolRC = FSO.FolderExists(sFolderPath)
If Not boolRC Then
Set FSO = Nothing
Set GetLastModifiedFile = Nothing
Exit Function
End If
Set objFolder = FSO.GetFolder(sFolderPath)
If objFolder.Files.Count = 0 Then
Set FSO = Nothing
Set objFolder = Nothing
Set GetLastModifiedFile = Nothing
Exit Function
End If
Set objFileResult = Nothing
longDateTime = CDate(0)
For Each objFile in objFolder.Files
If objFile.DateLastModified > longDateTime Then
Set objFileResult = objFile
longDateTime = objFile.DateLastModified
End If
Next
Set FSO = Nothing
Set objFolder = Nothing
Set GetLastModifiedFile = objFileResult
End Function


3 responses to "How to find last modified file (TestComplete, QTP, VBScript)"
Thanks. it’s useful website…..
Hi,
Do you know the script to get last modified file from a WebTable?
Cheers,
Matt
[ Albert’s reply.
Hi, Matt..
I don’t “know” scripts, I develop them – based on context.
If one can’t clearly understand a context, there’s a high chance of implementing invalid solution.
Your question is clearly lack of context. You wanna help me out here?
– Albert ]
Hi,How can i get the latest file from the folder.
file names will be as below.
DSINLOAD.J44006
DSINLOAD.J44007
DSINLOAD.J44008
but created on the same day with diff time…and file names start with DSINLOAD it can end up with any extension.