Results 1 to 3 of 3
  1. #1
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    Serbia and Montenegro (Yugoslavia)
    Posts
    342
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Get latest file in directory (VB6)

    I have an application where I want to auto fill a text box with the path of the last file entered into a directory. There is another application where I DIM'd Fil As Scripting.File and Fld As Scripting.Folder then iterated through each file loading the name or whatever attributes into an ADODB recordset with this type of loop:

    For Each fil In fld.Files

    ' right$("string", length)

    sShortFileName = Mid$(fil.Name, 1, InStr(fil.Name, ".") - 1)
    ''' sScanDate = Format(fil.DateLastModified, "mm/dd/yyyy")
    '''
    ''' sFinalEntry = sScanDate & Space(4) & sShortFileName

    .AddNew

    rsFileNames(0).Value = sShortFileName ' sFinalEntry


    Next fil

    End With

    In the application I'm working on now I want to turn this into a function that returns only the last file name, the one with the greatest date Create Date attribute, entered into a given directory.

  2. #2
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Get latest file in directory (VB6)

    Maybe there's a modern way to do this, but in the absence of other inspiration, I would go through the collection storing the "latest we know us as of this moment" until you finish checking them all.

    -Store first file name (strName) and create date (datCreated)
    -Check next created date; if later, store the new file name in strName and the new create date in datCreated
    -Repeat until no more files

  3. #3
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    Serbia and Montenegro (Yugoslavia)
    Posts
    342
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Get latest file in directory (VB6)

    By the way, I did exactly what you suggested and it worked perfectly. Thanks again for your help

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •