Results 1 to 5 of 5
  1. #1
    Silver Lounger
    Join Date
    Jun 2002
    Location
    Cheadle, Staffordshire
    Posts
    2,177
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Return Folder List (VB6)

    Is there a way to return filenames from a designated folder using the Date ?

    I was wanting to maybe attach some code to a command button.
    Daily I check a particular folder for additions of the previous day, I can then write the list down and view the files.
    My only concern is the dates in the folder details are in the "Now" format, would this prove to be difficult ?

  2. Get our unique weekly Newsletter with tips and techniques, how to's and critical updates on Windows 7, Windows 8, Windows XP, Firefox, Internet Explorer, Google, etc. Join our 480,000 subscribers!

    Excel 2013: The Missing Manual

    + Get this BONUS — free!

    Get the most of Excel! Learn about new features, basics of creating a new spreadsheet and using the infamous Ribbon in the first chapter of Excel 2013: The Missing Manual - Subscribe and download Chapter 1 for free!

  3. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 16 Times in 16 Posts

    Re: Return Folder List (VB6)

    If you are allowed to use scripting, you could do the following:
    - Select Project | References...
    - Set a reference to Microsoft Scripting Runtime
    - Use code like the following (it is for a command button cmdList and a list box lstFiles; the folder name is just an example)

    Private Sub cmdList_Click()
    Dim fso As New Scripting.FileSystemObject
    Dim fld As Scripting.Folder
    Dim fil As Scripting.File
    Set fld = fso.GetFolder("C:Images")
    For Each fil In fld.Files
    ' Check for modified date after day before yesterday
    If Int(fil.DateLastModified) > Date - 2 Then
    Me.lstFiles.AddItem fil.Name
    End If
    Next fil
    Set fil = Nothing
    Set fld = Nothing
    Set fso = Nothing
    End Sub

    Of course, you should adapt this to your situation and your needs.

  4. #3
    Silver Lounger
    Join Date
    Jun 2002
    Location
    Cheadle, Staffordshire
    Posts
    2,177
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Return Folder List (VB6)

    Hans
    This looks exactly as I need, Thanks.

  5. #4
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Return Folder List (VB6)

    I'm not sure if you want to return files ONLY if they satisfy a date, or whether you'd be happy obtaining ALL files and THEN testing for date. I do the latter.

    Below is a snippet of code I use for checking which of two files should be considered - the FileDateTime returns a Date with the time stamp of the file named as the string.
    One can always coerce a day.time value to a day value using the INTeger function, right?

    <pre>Dim dt1 As Date
    Dim dt2 As Date
    dt1 = FileDateTime(strTARGET & strList(lng1))
    dt2 = FileDateTime(strTARGET & strList(lng2))
    Dim strNewName As String
    If dt1 < dt2 Then ' move lower "dt1"
    etc. etc.
    </pre>


  6. #5
    Silver Lounger
    Join Date
    Jun 2002
    Location
    Cheadle, Staffordshire
    Posts
    2,177
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Return Folder List (VB6)

    Chris
    Thanks for the additional input.
    I've used Hans's example purely because the form this resides on has no importance other than saving me a little browsing.
    The info it returns doesn't need to be used elsewher and won't exist on the final EXE

    Thanks again

Posting Permissions

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