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

while using Keyward driven framework in QTPif new requirements are added how to manage it...plz ans

1572


Explain few date functions in vbscript?

616


How to delete a cookie using vbscript?

555


Hi anyone Can Send Solution to the Question wt m posting now Prepare Script for the Bellow Scenario? Login to Gmail Page Open Inbox check Mails save them in a Folder

1578


Which function allows you to instantiate an object given its programmatic identifier or progid?

562






How will you get a combined string from array of string in vbscript?

551


What methods are used to create text files and open text files in the vbscript language?

538


Hi Friends my Question is very simple,in Manual testing when we click on a hyper link it directs us to the relavent page or it re-directs us to the current page,so there we can easily write testcase but same thing if we do in automation script using QTP & need to generate report using Reporter.report event how we will do it?thanks in advance...

1657


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

574


what is inner join? what is outer join? what is a constraint? tell me about rdbms? tell me about acid properties?

1438


Explain what is loose binding? Why is it not a good practice to use it?

583


Give me sm ideas to write Vbscripts abt protocol testing abilash700@gmail.com.

1594


Which operator is used to concatenate the 2 values in the vbscript language?

562


What is the difference between javascript and vbscript?

536


What are the different types of loops available in the vbscript language?

536