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

Is vbscript language a case-sensitive language and what does it mean?

550


What is the difference between javascript and vbscript?

535


How should i Create Email invite with server-side Coding?

1604


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

614


Which object is used to work with the excel sheets in the vbscript language and what statement is used to create this object?

486






What is the output of a + b in vbscript if a = 5 and b = 10?

2123


Explain the string concatenation function in vbscript?

544


Which in-built function related to an array joins substrings into one string in the vbscript language?

520


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

1667


after medical test,when will be the police verification

1718


If a calulator having 3 buttons (of any number)in 3 of them one is not working properly due to which answer is wrong always. write a script to find out which button is not working properly ?

1564


Explain a few date functions in vbscript

558


How to Import data from a file (file is on the desktop) to the data table

1587


How to make professional test report using vbscript code in UFT, which gives us complete analysis of the test.

2500


create a form to accept username and password validate the username and password with using message box, display the corresponding user message

2163