Consulting

Results 1 to 2 of 2

Thread: FileDateTime Question

  1. #1

    FileDateTime Question

    If I wanted to print to a text file (I know how to do this piece) all files in a directory that were modified between 8 p.m. 06/12/2014 and 11 p.m. on 06/13/2014 how would I set up that syntax? All I am unclear on is the FileDateTime portion. I know to only do a date I could use this and it would be all files from today, but how do I set-up the time piece and do a range like I need to?
    Int(FileDateTime(File)) = Date

  2. #2
    Knowledge Base Approver VBAX Guru GTO's Avatar
    Joined
    Sep 2008
    Posts
    3,368
    Location
    Hi Richard,

    I chose different dates/time, and I realize you are probably not using FSO, but does this help demonstrate it?

    Option Explicit
      
    Sub Example()
    Dim fsoFile As Object ' Scripting.File
    Dim dblEarliestDate As Double, dblLatestDate As Double
      
      dblEarliestDate = #5/29/2014# + #2:00:00 AM#
      dblLatestDate = #6/12/2014# + #9:10:00 PM#
      
      
      For Each fsoFile In CreateObject("Scripting.FileSystemObject").GetFolder("F:\Tents VBA Projects\Schedule\").Files
        
        If CDbl(FileDateTime(fsoFile.Path)) >= dblEarliestDate _
        And CDbl(FileDateTime(fsoFile.Path)) <= dblLatestDate Then
          
          Debug.Print fsoFile.Name & Space(100 - Len(fsoFile.Name)) & FileDateTime(fsoFile.Path)
          
        End If
        
      Next
      
    End Sub
    I personally would test to make sure the string can convert to a date. I'm in Arizona and would not likely need to worry about different settings, but if that is a concern, then I think you can check the registry with API functions to ensure the date is read correctly.

    Hope that helps,

    Mark

Posting Permissions

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