Published in: Visual Basic
msgbox GetNewestFile("c:\tmp") Function GetNewestFile(ByVal sPath) Set oFSO = CreateObject("Scripting.FileSystemObject") 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
You need to login to post a comment.
