/ Published in: Visual Basic
retrieves newest edited file in specified directory (optional file extension)
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
Public Function NewestFile(Directory As String, FileSpec As String) As String ' Returns the name of the most recent file in a Directory ' That matches the FileSpec (e.g., "*.xls"). ' Returns an empty string if the directory does not exist or ' it contains no matching files ' all files : "*.*" Dim FileName As String Dim MostRecentFile As String Dim MostRecentDate As Date If Right(Directory, 1) <> "\" Then Directory = Directory & "\" FileName = Dir(Directory & FileSpec, 0) If FileName <> "" Then MostRecentFile = FileName MostRecentDate = FileDateTime(Directory & FileName) Do While FileName <> "" If FileDateTime(Directory & FileName) > MostRecentDate Then MostRecentFile = FileName MostRecentDate = FileDateTime(Directory & FileName) End If FileName = Dir Loop End If NewestFile = Directory & MostRecentFile End Function