08-30-2010, 02:33 PM
Hi,
I have posted some time back related to this kind of query but not exactly same. I hope it will helps you below code. Dont follow exact code. I just gave for your reference for reading file from folder.
For details refer below link:
https://www.learnqtp.com/forums/Thread-H...t=function
I have posted some time back related to this kind of query but not exactly same. I hope it will helps you below code. Dont follow exact code. I just gave for your reference for reading file from folder.
For details refer below link:
https://www.learnqtp.com/forums/Thread-H...t=function
Code:
Function GetNewestFile(ByVal sPath)
sNewestFile = Null ' init value
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oFolder = oFSO.GetFolder(sPath)
Set oFiles = oFolder.Files
' enumerate the files in the folder, finding the newest file
For Each oFile In oFiles
On Error Resume Next
If IsNull(sNewestFile) Then
sNewestFile = oFile.Path
dPrevDate = oFile.DateLastModified
Elseif dPrevDate < oFile.DateLastModified Then
sNewestFile = oFile.Path
End If
On Error Goto 0
Next
If IsNull(sNewestFile) Then sNewestFile = ""
GetNewestFile = sNewestFile
End Function
sPath = "c:\my test" 'Here my test is the folder name
Set oFSO = CreateObject("Scripting.FileSystemObject")
sNewestFile = GetNewestFile(sPath)
If sNewestFile <> "" Then
WScript.Echo "Newest file is " & sNewestFile
Else
WScript.Echo "Directory is empty"
End If