From: LondonLad on
I got this code on google the owner could be Brian S or FlyGuy I have
modified to suit but I am getting an incorrect date returned.

If I search for 2 folder dates on the same Drive I get the correct answers
for both folders, if I search for folders on different Drives I get the
correct date on the first folder, and the incorrect date on the second folder
of 02/01/1601 22:00:00 which is most likely the prime first date.

Is there a work around for this?
I have tried to clear the Vars but this did not work.

Thanks
From: ralph on
On Sun, 25 Jul 2010 09:35:21 -0700, LondonLad
<LondonLad(a)discussions.microsoft.com> wrote:

>I got this code on google the owner could be Brian S or FlyGuy I have
>modified to suit but I am getting an incorrect date returned.
>
>If I search for 2 folder dates on the same Drive I get the correct answers
>for both folders, if I search for folders on different Drives I get the
>correct date on the first folder, and the incorrect date on the second folder
>of 02/01/1601 22:00:00 which is most likely the prime first date.
>
>Is there a work around for this?
>I have tried to clear the Vars but this did not work.
>
>Thanks

It might be useful to know what code you 'got'?

If you are using Dir() there are a number of Gotchas associated with
it. Doing a web search for "VB Dir problems" will return a list of
them.

-ralph
From: LondonLad on
Missing Code

Option Explicit
Private Type WIN32_FIND_DATA
dwFileAttributes As Long
ftCreationTime As Currency
ftLastAccessTime As Currency
ftLastWriteTime As Currency
nFileSizeHigh As Long
nFileSizeLow As Long
dwReserved0 As Long
dwReserved1 As Long
cFileName As String * 260
cAlternate As String * 14
End Type

' Difference between day zero for VB dates and Win32 dates
' (or #12-30-1899# - #01-01-1601#)
Const rDayZeroBias As Double = 109205# ' Abs(CDbl(#01-01-1601#))

' 10000000 nanoseconds * 60 seconds * 60 minutes * 24 hours / 10000
' comes to 86400000 (the 10000 adjusts for fixed point in Currency)
Const rMillisecondPerDay As Double = 10000000# * 60# * 60# * 24# / 10000#

Private Declare Function FileTimeToLocalFileTime Lib "kernel32.dll"
(lpFileTime _
As Currency, lpLocalFileTime As Currency) As Long
Private Declare Function FindFirstFile Lib "kernel32" Alias "FindFirstFileA" _
(ByVal lpFileName As String, lpFindFileData As WIN32_FIND_DATA) As Long
Private Declare Function FindClose Lib "kernel32" (ByVal hFindFile As Long)
As _
Long

Private Sub Form_Load()
Dim datModified(1) As Date, datCreated(1) As Date, datAccessed(1) As Date
Dim sFile As String, s1File As String

sFile = "C:\CD Burn"
datModified(0) = FileAnyDateTime(sFile, datCreated(0), datAccessed(0))

sFile = "D:\Delete OMX"
datModified(1) = FileAnyDateTime(sFile, datCreated(1), datAccessed(1))


Text1.Text = datModified(0)
Text2.Text = datModified(1)

' Debug.Print "DateTime Modified:", datModified(0)
' Debug.Print "DateTime Modified:", datModified(1)
' Debug.Print "DateTime Created: ", datCreated
' Debug.Print "DateTime Accessed:", datAccessed
End Sub

Function FileAnyDateTime(sPath As String, datCreation As Date, datAccess As
Date) As Date

Dim fnd As WIN32_FIND_DATA
Dim hFind As Long, f As Boolean

' Get all three times in UDT
hFind = FindFirstFile(sPath, fnd)
'If hFind = hInvalid Then ApiRaise Err.LastDllError

FindClose hFind
hFind = 0

' Convert them to Visual Basic format
datCreation = Win32ToVbTime(fnd.ftCreationTime)
datAccess = Win32ToVbTime(fnd.ftLastAccessTime)
FileAnyDateTime = Win32ToVbTime(fnd.ftLastWriteTime)
End Function


Function Win32ToVbTime(ft As Currency) As Date
Dim ftl As Currency
' Call API to convert from UTC time to local time
If FileTimeToLocalFileTime(ft, ftl) Then
' Local time is nanoseconds since 01-01-1601
' In Currency that comes out as milliseconds
' Divide by milliseconds per day to get days since 1601
' Subtract days from 1601 to 1899 to get VB Date equivalent
Win32ToVbTime = CDate((ftl / rMillisecondPerDay) - rDayZeroBias)
Else
Debug.Print Err.LastDllError
End If
End Function


"LondonLad" wrote:

> I got this code on google the owner could be Brian S or FlyGuy I have
> modified to suit but I am getting an incorrect date returned.
>
> If I search for 2 folder dates on the same Drive I get the correct answers
> for both folders, if I search for folders on different Drives I get the
> correct date on the first folder, and the incorrect date on the second folder
> of 02/01/1601 22:00:00 which is most likely the prime first date.
>
> Is there a work around for this?
> I have tried to clear the Vars but this did not work.
>
> Thanks