Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Create-Access-Modified FileDate NTFS4/NTFS5

Status
Not open for further replies.

bashless

Technical User
May 3, 2002
35
0
0
US
Folks;

I am having difficulty creating the "perfect" methods to retrieve the correct file creation, last access, and last modification (write) dates+time.

Does anyone out there have a routine that will give the correct date/time stamps for files accessed locally or remotely on the following os's:
Win9x, WinME, WinXP, WinNT3/4/5 (NTFS4 and NTFS5)

Also, I see that OPENFILE is no longer preferred for win2k compatibility, are you all using CREATEFILE to get the filehandle?

THanks..

Oh...these are what I have been banging my head on....

FileTimeToSystemTime
FileTimeToLocalFileTime
SystemTimeToTzSpecificLocalTime
SystemTimeToFileTime
GetSystemTimeAsFileTime
..
ouch!
 
Hi bashless,

put the code in a form:


Public Enum EFileAttributes
faArchive = &H20&
faCompressed = &H800&
faDirectory = &H10&
faHidden = &H2&
faNormal = &H80&
faReadOnly = &H1&
faSystem = &H4&
faTemporary = &H100&
End Enum

Public Enum EFileAccessModes
famQuery = 0&
famGenericRead = &H80000000
famGenericWrite = &H40000000
famGenericExecute = &H20000000
famGenericAll = &H10000000
End Enum

Public Enum EFileShareModes
fsmShareNone = 0&
fsmShareRead = 1&
fsmShareWrite = 2&
fsmShareDelete = 4&
End Enum

Public Enum EFileCreationMode
fcmCreateNew = 1&
fcmCreateAlways = 2&
fcmOpenExisting = 3&
fcmOpenAlways = 4&
fcmTruncateExisting = 5&
End Enum

Private Type TFileTime
dwLowDateTime As Long
dwHighDateTime As Long
End Type

Private Type TSystemTime
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

Private Declare Function CreateFile Lib "kernel32" Alias "CreateFileA" (ByVal lpFileName As String, ByVal dwDesiredAccess As Long, ByVal dwShareMode As Long, lpSecurityAttributes As Any, ByVal dwCreationDisposition As Long, ByVal dwFlagsAndAttributes As Long, ByVal hTemplateFile As Long) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Private Declare Function GetFileTime Lib "kernel32" (ByVal hFile As Long, lpCreationTime As TFileTime, lpLastAccessTime As TFileTime, lpLastWriteTime As TFileTime) As Long
Private Declare Function FileTimeToSystemTime Lib "kernel32" (lpFileTime As TFileTime, lpSystemTime As TSystemTime) As Long


Private Sub Form_Load()
Dim FileName As String
Dim hFile As Long
Dim ftFileCreation As TFileTime
Dim ftFileLastAccess As TFileTime
Dim ftFileLastWrite As TFileTime
Dim stFileCreation As TSystemTime
Dim stFileLastAccess As TSystemTime
Dim stFileLastWrite As TSystemTime

FileName = "c:\autoexec.bat"
hFile = CreateFile(FileName, famGenericRead, fsmShareRead, ByVal 0&, fcmOpenExisting, faNormal, 0&)
If hFile = -1 Then Exit Sub

GetFileTime hFile, ftFileCreation, ftFileLastAccess, ftFileLastWrite
CloseHandle hFile

FileTimeToSystemTime ftFileCreation, stFileCreation
FileTimeToSystemTime ftFileLastAccess, stFileLastAccess
FileTimeToSystemTime ftFileLastWrite, stFileLastWrite
With stFileCreation
Debug.Print "FileCreation:" & Format(.wDay & "." & .wMonth & "." & .wYear & " " & .wHour & ":" & .wMinute & ":" & .wSecond, "dd.mm.yyyy hh:nn:ss")
End With
With stFileLastAccess
Debug.Print "FileLastAccess:" & Format(.wDay & "." & .wMonth & "." & .wYear & " " & .wHour & ":" & .wMinute & ":" & .wSecond, "dd.mm.yyyy hh:nn:ss")
End With
With stFileLastWrite
Debug.Print "FileLastWrite:" & Format(.wDay & "." & .wMonth & "." & .wYear & " " & .wHour & ":" & .wMinute & ":" & .wSecond, "dd.mm.yyyy hh:nn:ss")
End With
End Sub

Bye
LauDse
 
Sorry....wrong answer! ....I was hoping.

Even with this code I am getting <various> an error of +4 hours. If I manually subtract (from the fields that read somewhat correctly as I am EST) I get UTC. This error is consistent for two win2k pc's and WinME. So anyone have any good ideas? I think this is one of those NTFS issues though I am not sure about the WinME disk format.

Reading_OS File_OS Create Access Modified

Win2KSP3 Win2KSP3 UTC UTC UTC <Same PC>
Win2KSP3 Win2KSP3 UTC Bad UTC <2 PC's>
Win2KSP3 WinME Bad Bad UTC

I am using VB6 Enterprise SP5, running on Win2K SP3.

I would be interested in knowing if others have the same results. Email me and I will send the .vpb, .frm, and .bas files for this project.

There was a note in msdn <look at this link>

That talked about using the following sequence of functions to return the correct time.

excerpt...

Remarks
FileTimeToLocalFileTime uses the current settings for the time zone and daylight saving time. Therefore, if it is daylight saving time, this function will take daylight saving time into account, even if the time you are converting is in standard time. To account for daylight saving time when converting a file time to a local time, use the following sequence of functions instead of FileTimeToLocalFileTime:

FileTimeToSystemTime
SystemTimeToTzSpecificLocalTime
SystemTimeToFileTime

I am lost....I tried this sequence but got garbage.

Anyone up for a challenge?????

NOSPAMrob@NOSPAMmethodsNOSPAMDevelopment.com

(remove the nospam for my real email address)

Thanks..
 
Making Headway....

It appears that the modified date is the only stable element so far across OS's...of course if someout there has a cross os routine feel free to share!

Here is what works for the modified date:

CreateFile
GetFileTime(handle, create, access, modified)
FileTimeToLocalFileTime <for each time element>
FileTimeToSystemTime <user readable time>

At least with this the modified time appears to match.

Anybody else beat their head over this? (Bill G?)

Rob
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top