Hallo Leute,
ich versuche von Dateien die Zeiten (Create/Access/Write) zu lesen. Dazu verwende ich diesen Code (VB .NET 2005):
' -- API --
Public Structure FILETIME
Public dwLowDateTime As Integer
Public dwHighDateTime As Integer
End Structure
Private Structure SYSTEMTIME
Public wYear As Integer
Public wMonth As Integer
Public wDayOfWeek As Integer
Public wDay As Integer
Public wHour As Integer
Public wMinute As Integer
Public wSecond As Integer
Public wMilliseconds As Integer
End Structure
<DllImport("kernel32.dll")> _
Private Shared Function CreateFile( _
<MarshalAs(UnmanagedType.LPStr)> ByVal lpFileName As String, _
ByVal dwDesiredAccess As Access, _
ByVal dwShareMode As ShareMode, _
ByVal lpSecurityAttributes As Integer, _
ByVal dwCreationDisposition As CreationDisposition, _
ByVal dwFlagsAndAttributes As FlagsAndAttributes, _
ByVal hTemplateFile As Integer) As Integer
End Function
<DllImport("kernel32.dll")> _
Private Shared Function CloseHandle( _
ByVal hObject As Integer) As Integer
End Function
<DllImport("kernel32.dll")> _
Private Shared Function FileTimeToSystemTime( _
ByRef lpFileTime As FILETIME, _
ByRef lpSystemTime As SYSTEMTIME) As Integer
End Function
<DllImport("kernel32.dll")> _
Private Shared Function FileTimeToLocalFileTime( _
ByRef lpFileTime As FILETIME, _
ByRef lpLocalFileTime As FILETIME) As Integer
End Function
<DllImport("kernel32.dll")> _
Private Shared Function GetFileTime( _
ByVal hFile As Integer, _
ByRef lpCreationTime As FILETIME, _
ByRef lpLastAccessTime As FILETIME, _
ByRef lpLastWriteTime As FILETIME) As Integer
End Function
' Hier wirds interessant
Private Shared Function GetFileTimes(ByVal path As String) As Date()
'Datei öffnen
Dim hf As Integer = CreateFile(path, Access.Read, ShareMode.Read, 0, _
CreationDisposition.OpenExisting, FlagsAndAttributes.AttributeNormal, _
0)
Dim ft(2) As FILETIME
'Zeiten auslesen
GetFileTime(hf, ft(0), ft(1), ft(2))
Dim time(2) As SYSTEMTIME
Dim d(2) As Date
Dim i As Integer
For i = 0 To ft.Length - 1
'Nach diesen beiden Aufrufen stehen in time(...) unbrauchbare
' Werte...
FileTimeToLocalFileTime(ft(i), ft(i))
FileTimeToSystemTime(ft(i), time(i))
'time(0) sieht jetzt so aus:
'wDay = 41287708
'wDayOfWeek = 917519
'wMonth 851970
'wYear 722903
'der Rest ist 0
d(i) = New Date(time(i).wYear, time(i).wMonth, time(i).wDay, time( _
i).wHour, time(i).wMinute, time(i).wSecond)
Next
CloseHandle(hf)
Return d
End Function Warum kommen da solche Werte raus? Was mache ich falsch?
Nachtrag:
Ich lese da Dateien aus einer Schattenkopie, weshalb ich auch die WinAPI nutze und nciht direkt .NET.
Bei "normalen" Dateien kommen die selben komischen Werte raus.
Beitrag wurde zuletzt am 16.05.08 um 12:32:38 editiert. |