Look up file by date/time stamp.

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
 
R

Rick Rothstein \(MVP - VB\)

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top