How to get latest file in a folder

Hello friends!!

Here is a brief code for getting latest/newest file in a particular folder/directory…

Dim LatestFile
Set oFolder=CreateObject(“scripting.FileSystemObject”).GetFolder(“E:Dwnld”)
For Each eachFile In oFolder.Files
    If LatestFile = “” Then
        Set LatestFile = eachFile
    Else If LatestFile.DateCreated < eachFile.DateCreated Then
            Set LatestFile = eachFile
        End If
    End If

Msgbox LatestFile.Name

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top