File_MostRecent

Getting most recent file in a folder

CodeFunctionName
What is this?

Public

Tested

Original Work
Function File_MostRecent(Optional InFolder = "")
If InFolder = "" Then InFolder = FixPath()
Set fso = CreateObject("Scripting.FileSystemObject")
Set fo = fso.GetFolder(InFolder)
Recent1 = 0
RecentN = ""
For Each x In fo.Files
Recent2 = CDate(CLng(x.DateLastModified))
ThisFileName = x.Name
Ignore1 = Not ThisFileName = "Thumbs.db" ' we do not need to consider this file.... all conditions must be true
Ignore2 = Not Left(ThisFileName, 2) = "~$" ' temporary files... all must be true
Ignore3 = Not ThisFileName = "Desktop.ini" ' not this either... all must be true
If Recent2 > Recent1 And Ignore1 And Ignore2 And Ignore3 Then
Recent1 = Recent2
RecentN = ThisFileName
End If
Next
File_MostRecent = RecentN
End Function

InFolder

Views 4,428

Downloads 1,325

CodeID
DB ID

ANmarAmdeen
609
Revisions

v2.0

Wednesday
July
18
2018