Files in a folder

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Bo Wisén

    #1

    Files in a folder

    Hi,

    Let's say I've some files in a folder with the same suffix, for example
    ..abc. Is there anyway I can let VB decide which one of them that is the
    newest?

    / Bosse



  • Rick Rothstein

    #2
    Re: Files in a folder

    > Let's say I've some files in a folder with the same suffix, for
    example[color=blue]
    > .abc. Is there anyway I can let VB decide which one of them that is[/color]
    the[color=blue]
    > newest?[/color]

    Run this code...

    Dim Path As String
    Dim Suffix As String
    Dim FileName As String
    Dim LatestFile As String
    Dim LatestDate As Date
    Path = "c:\temp\" ' Note the trailing backslash
    Suffix = "abc" ' Note there is no leading dot
    FileName = Dir$(Path & "*." & Suffix)
    Do While Len(FileName)
    If FileDateTime(Pa th & FileName) > LatestDate Then
    LatestFile = Path & FileName
    LatestDate = FileDateTime(Pa th & FileName)
    End If
    FileName = Dir$
    Loop

    and your file's name will be in the LatestFile variable and its
    date/time stamp will be in the LatestDate variable.

    Rick - MVP

    Comment

    Working...