Pages

Tuesday, December 18

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
Next

Msgbox LatestFile.Name