PDA

View Full Version : [SOLVED] FileDateTime Question



richardSmith
06-14-2014, 07:58 PM
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

GTO
06-15-2014, 03:23 AM
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