Look up file by date/time stamp.

  • Thread starter Thread starter Rpettis31
  • Start date Start date
R

Rpettis31

How would I open a file by the date and or time stamp on the file?

Occassionally I receive a downloaded file that is in a text format
These files are received daily 2x a day. The filename is typically.
GEN-filename-month-day-year-random number.txt

I believe the easiest technique is to open a file with these parameters is
to open with GEN-filename-* {asterix being a wild card} and then look for the
time date stamp to pull the newest file.

Thanks
 
Give this code snippet a try (just incorporate it into your current code...

Dim Path As String
Dim Filename As String
Dim LatestFileName As String
Dim LatestFileDate As Date
' Note: The path must always end with a backslash
Path = "c:\temp\"
Filename = Dir$(Path & "GEN-filename-*.txt")
Do While Len(Filename) > 0
If FileDateTime(Path & Filename) > LatestFileDate Then
LatestFileName = Path & Filename
LatestFileDate = FileDateTime(Path & Filename)
End If
Filename = Dir$
Loop
'
' LatestFileName contains the path/filename of the most
' recent file, so Open it and do what you need to with it
'

Rick
 
Back
Top