Link to home
Start Free TrialLog in
Avatar of joebenz
joebenz

asked on

Newest file in a folder

How to find the newest file in a folder
ASKER CERTIFIED SOLUTION
Avatar of shancock
shancock

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of joebenz
joebenz

ASKER

To Shancock

Let me try it
Avatar of Richie_Simonetti
Private Sub Form_Load()
Dim fso, ffolder, ffile
Dim dd As Date, sFilename As String
Set fso = CreateObject("Scripting.FileSystemObject")
Set ffolder = fso.getfolder("c:\")
For Each ffile In ffolder.Files
    If ffile.datecreated > dd Then
        sFilename = ffile.Name
        dd = ffile.datecreated
       
    End If
Next
MsgBox sFilename
End Sub
too slow!!
Avatar of joebenz

ASKER

Although both are almost the same (Richie and Shanock),

Shanock is retuned the correct value
Avatar of joebenz

ASKER

To Richie,
 I do not know why yours is 3 files short to the newest.
first of all, what do you need last modification date(shancock ) or which is the newest file?
I didn't  get what you get, i got the last file that was created in that folder.
Cheers
Avatar of joebenz

ASKER

To Richie

I ran both on 4 different folders and yet yours did not return the latest file.
Sorry
Avatar of joebenz

ASKER

To all,
I have to go.