[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.vb.general.discussion

File last write time wrong

BeeJ

12/10/2011 2:55:00 AM

File time is way off.
What am I missing?

Windows Explorer Date Modified 12/9/2011 5:43 PM
Size 4 KB
And this agrees with the time I modified the file.

But File Find WFD.ftLastWriteTime winds up with this time after
calling the FileTimeSortable function.
.wDay is wrong by one day, the next day.
also the time .wHour is off.
Yes, I know that one is 12 hr and the other is 24 hr format.

year 2011
month 12
day 10

hour 1
minute 43
second 50

Size 3270

Call my sub
FileTimeSortable(WFD.ftLastWriteTime)

Private Function FileTimeSortable(ByRef tFTime As FILETIME) As String

Dim tSTime As SYSTEMTIME
Const cs00 As String = "00"
Const cs0000 As String = "0000"
Dim dNow As Date

If FileTimeToSystemTime(tFTime, tSTime) <> 0 Then
With tSTime
FileTimeSortable = Format$(.wYear, cs0000) & csSlh & _
Format$(.wMonth, cs00) & csSlh & _
Format$(.wDay, cs00) & csSp1 & _
Format$(.wHour, cs00) & csCln & _
Format$(.wMinute, cs00) & csCln & _
Format$(.wSecond, cs00)


<snip>

Private Type FILETIME
dwLowDateTime As Long
dwHighDateTime As Long
End Type
'
Private Type SYSTEMTIME
wYear As Integer
wMonth As Integer
wDayOfWeek As Integer
wDay As Integer
wHour As Integer
wMinute As Integer
wSecond As Integer
wMilliseconds As Integer
End Type
'
MSDN notes
' Not all file systems can record creation and last access time
' and not all file systems record them in the same manner.
' For example, on NT FAT, create time has a resolution of 10
milliseconds,
' write time has a resolution of 2 seconds,
' and access time has a resolution of 1 day (really, the access
date).
' On NTFS, access time has a resolution of 1 hour.



.
6 Answers

JPB

12/10/2011 4:27:00 PM

0

System Time is in Coordinated Universal Time (UTC), you will need to
convert it to local time based on the system's time zone.

On Dec 9, 9:55 pm, BeeJ <nos...@spamnot.com> wrote:
> File time is way off.
> What am I missing?
>
> Windows Explorer Date Modified  12/9/2011 5:43 PM
>                  Size 4 KB
> And this agrees with the time I modified the file.
>
> But File Find WFD.ftLastWriteTime winds up with this time after
> calling the FileTimeSortable function.
>   .wDay is wrong by one day, the next day.
> also the time .wHour is off.
> Yes, I know that one is 12 hr and the other is 24 hr format.
>
>   year 2011
>   month 12
>   day   10
>
>   hour   1
>   minute 43
>   second 50
>
>   Size 3270
>
> Call my sub
>   FileTimeSortable(WFD.ftLastWriteTime)
>
> Private Function FileTimeSortable(ByRef tFTime As FILETIME) As String
>
>     Dim tSTime      As SYSTEMTIME
>     Const cs00      As String = "00"
>     Const cs0000    As String = "0000"
>     Dim dNow        As Date
>
>     If FileTimeToSystemTime(tFTime, tSTime) <> 0 Then
>         With tSTime
>             FileTimeSortable = Format$(.wYear, cs0000) & csSlh & _
>                                 Format$(.wMonth, cs00) & csSlh & _
>                                 Format$(.wDay, cs00) & csSp1 & _
>                                 Format$(.wHour, cs00) & csCln & _
>                                 Format$(.wMinute, cs00) & csCln & _
>                                 Format$(.wSecond, cs00)
>
> <snip>
>
> Private Type FILETIME
>    dwLowDateTime    As Long
>    dwHighDateTime   As Long
> End Type
> '
> Private Type SYSTEMTIME
>     wYear           As Integer
>     wMonth          As Integer
>     wDayOfWeek      As Integer
>     wDay            As Integer
>     wHour           As Integer
>     wMinute         As Integer
>     wSecond         As Integer
>     wMilliseconds   As Integer
> End Type
> '
> MSDN notes
> ' Not all file systems can record creation and last access time
> '   and not all file systems record them in the same manner.
> ' For example, on NT FAT, create time has a resolution of 10
> milliseconds,
> '   write time has a resolution of 2 seconds,
> '   and access time has a resolution of 1 day (really, the access
> date).
> ' On NTFS, access time has a resolution of 1 hour.
>
> .

BeeJ

12/10/2011 9:20:00 PM

0

Strangly other dates seemed to be OK and since other dates seemed OK it
did not occurr to me that there was a "global" problem.


BeeJ

12/10/2011 9:33:00 PM

0

So the related question is:
I get file time as Type
Public Type FILETIME
dwLowDateTime As Long
dwHighDateTime As Long
End Type

I want to quickly store this for later comparison but first convert it
to something sortable.
Simple example is convert it to a date and then format it using
something like Format$(date, "yyyymmdd hhnnss").
But that seems like too much processing.

(1) If I take the dwLowDateTime and dwHighDateTime and convert it to a
decimal (double long) does that represent a sortable date?
(2) And do the Type Longs ever have the &H80000000 bit set?
MSDN does not clarify for me.

Not sure I understand the Type.

dwLowDateTime
Specifies the low 32 bits of the Win32 date/time value.
dwHighDateTime
Specifies the upper 32 bits of the Win32 date/time value.

Public Function LongsToDec(lLo As Long, lHi As Long) As Variant

' This function converts the Lo+Hi Longs to a Decimal
Dim vLo As Variant
Dim vHi As Variant

vLo = CDec(0)
vHi = CDec(0)

If lLo And &H80000000 Then
vLo = curBit31 + (CDec(lLo) And &H7FFFFFFF)
Else
vLo = lLo
End If
If lHi And &H80000000 Then
vHi = curBit31 + CDec(lHi) And &H7FFFFFFF
Else
vHi = CDec(lHi)
End If

LongsToDec = CDec(vLo + vHi * (2 ^ 32))

End Function 'LongsToDec


Mike Williams

12/10/2011 10:58:00 PM

0

"BeeJ" <nospam@spamnot.com> wrote in message
news:jc0j72$8uq$1@speranza.aioe.org...

> (1) If I take the dwLowDateTime and dwHighDateTime and convert
> it to a decimal (double long) does that represent a sortable date?
> (2) And do the Type Longs ever have the &H80000000 bit set?
> MSDN does not clarify for me.

Both are unsigned Longs and so it is entirely possible for the highest order
bit to be set without it signifying a negative value. I don't do much with
File Times myself but I assume that you will be able to use a UDT containing
one Currency data type (rather than two Longs), or even just a currency data
type without it being in a UDT if you change the GetFileTime declaration
accordingly. In both cases you should then be able to simply sort the
Currency values.

Mike



BeeJ

12/10/2011 11:49:00 PM

0

Mike Williams has brought this to us :
> "BeeJ" <nospam@spamnot.com> wrote in message
> news:jc0j72$8uq$1@speranza.aioe.org...
>
>> (1) If I take the dwLowDateTime and dwHighDateTime and convert
>> it to a decimal (double long) does that represent a sortable date?
>> (2) And do the Type Longs ever have the &H80000000 bit set?
>> MSDN does not clarify for me.
>
> Both are unsigned Longs and so it is entirely possible for the highest order
> bit to be set without it signifying a negative value. I don't do much with
> File Times myself but I assume that you will be able to use a UDT containing
> one Currency data type (rather than two Longs), or even just a currency data
> type without it being in a UDT if you change the GetFileTime declaration
> accordingly. In both cases you should then be able to simply sort the
> Currency values.
>
> Mike

I give that a try.
Thanks Mike.


BeeJ

12/11/2011 9:36:00 PM

0

Working now. Thanks all!



--- Posted via news://freenews.netfront.net/ - Complaints to news@netfront.net ---