Avatar of joebenz
joebenz
 asked on

Newest file in a folder

How to find the newest file in a folder
Visual Basic ClassicVB Script

Avatar of undefined
Last Comment
joebenz

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
shancock

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
joebenz

ASKER
To Shancock

Let me try it
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
Richie_Simonetti

too slow!!
Your help has saved me hundreds of hours of internet surfing.
fblack61
joebenz

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

Shanock is retuned the correct value
joebenz

ASKER
To Richie,
 I do not know why yours is 3 files short to the newest.
Richie_Simonetti

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
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
joebenz

ASKER
To Richie

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

ASKER
To all,
I have to go.