How to find a latest file from any folder

Answer Posted / manjunathareddy

sPath="C:\FlightFrameWork"
Msgbox GetNewestFile(sPath)


Function GetNewestFile(ByVal sPath)

sNewestFile = Null

Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oFolder = oFSO.GetFolder(sPath)
Set oFiles = oFolder.Files
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

Is This Answer Correct ?    2 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

How do you declare a variable in vbscript?

618


Both Static and dynamic arrays are handled by VB script. Is it true?

603


Mention what if you do not specify anything when you call a procedure?

562


Explain about arrays in vb script?

596


What are the valid scopes of a variable in vbscript?

599






what is the use of QCUtil? explain with one example?

6311


Mention what is byref and byval parameters in vbscript?

570


What is event handling in vbscript?

589


PLz send me the VB scripts which is having more examples my email id : hareen_11@yahoo.com

1654


What are keywords in the vbscript language?

513


How will you format a number in percetage format in vbscript?

585


How do i automate a website www.flyashx.com without having any test cases witin a week time.

1443


What is the purpose of the err object in the vbscript language?

613


What is the difference between VBScript and JavaScript?

2045


what types of bugs will we find out in banking projects for automation testing?

1757