joebenz
asked on
Newest file in a folder
How to find the newest file in a folder
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Private Sub Form_Load()
Dim fso, ffolder, ffile
Dim dd As Date, sFilename As String
Set fso = CreateObject("Scripting.Fi leSystemOb ject")
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
Dim fso, ffolder, ffile
Dim dd As Date, sFilename As String
Set fso = CreateObject("Scripting.Fi
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!!
ASKER
Although both are almost the same (Richie and Shanock),
Shanock is retuned the correct value
Shanock is retuned the correct value
ASKER
To Richie,
I do not know why yours is 3 files short to the newest.
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
I didn't get what you get, i got the last file that was created in that folder.
Cheers
ASKER
To Richie
I ran both on 4 different folders and yet yours did not return the latest file.
Sorry
I ran both on 4 different folders and yet yours did not return the latest file.
Sorry
ASKER
To all,
I have to go.
I have to go.
ASKER
Let me try it