File Timestamp revisited

Since our last time change for Daylight saving I have written a program that compares the "filedatetime" on 2 computers & reports differences so that I can copy the relevant files to keep both synchronised.

The program has been working fine for the last 6 months, but now the NT administrator has changed the time on my NT computer (forward 1 hour) My program now reports every file is out by 1 hour.

Explorer is also showing the file time different by 1 hour, even though I know the two files are the same.

How can I use VB5 to check the real (as opposed to a conversion by VB) timestamp & compare them?
*********************************
*********************************

Vetranger supplied the following answer but I do not seem to get the correct answer as shown below


**********************************
**********************************

In the case of VB5, you can use the GetFileTime API, along with the filetimetosystemtime API to get the long variables returned by FILETIME into something you can recognize :

paste the stuff between the **** lines into a general declaractions of a module

**************
Public Type FILETIME
        dwLowDateTime As Long
        dwHighDateTime As Long
End Type

Public 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

Public Type WIN32_FIND_DATA
        dwFileAttributes As Long
        ftCreationTime As FILETIME
        ftLastAccessTime As FILETIME
        ftLastWriteTime As FILETIME
        nFileSizeHigh As Long
        nFileSizeLow As Long
        dwReserved0 As Long
        dwReserved1 As Long
        cFileName As String * MAX_PATH
        cAlternate As String * 14
End Type

Public Declare Function FindFirstFile Lib "kernel32" Alias "FindFirstFileA" (ByVal lpFileName As String, lpFindFileData As WIN32_FIND_DATA) As Long

Public Declare Function FindClose Lib "kernel32" Alias "FindClose" (ByVal hFindFile As Long) As Long

Public Declare Function FileTimeToSystemTime Lib "kernel32" Alias "FileTimeToSystemTime" (lpFileTime As FILETIME, lpSystemTime As SYSTEMTIME) As Long
*********************
Then in your procedure :

Dim myFileData as win32_find_data
dim mySysTime as systemtime
dim filehandle as long
dim ret as long
dim myFile as string

myFile = "c:\whatever\yourfile.ext"

filehandle = findfirstfile(myFile,myFileData)
ret = filetimetosystemtime(myFileData.ftlastaccesstime,mySysTime)
ret=findclose(filehandle)

Now the mySysTime structure should have the info you need. I wrote this up in the comment window, so if you find a glitch in it somewhere just post what's happening and I'll continue supporting the question.  
 

*********************************
*********************************

results are as follows:

Application run at 07:58:39 11-12-1999

FileDateTime = 21/07/97 21:18:38
Year  =  1999
Month  =  11
Weekday  =  5
Day  =  5
Hour  =  2
Minute  =  3
Second  =  3
Millisecond  =  930

it appears that app is reporting systen time not file time although I don't know how 2 represents 7am or 3 represents 58 (or 18 for file time)

Any further comments please
 
bemsonAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Erick37Commented:
Try this:

Dim wfd As WIN32_FIND_DATA
Dim ft As FILETIME
Dim st As SYSTEMTIME
Dim hFile As Long
Dim myFile As String

myFile = "c:\detlog.txt"

hFile = FindFirstFile(myFile, wfd)
If hFile = -1 Then
    MsgBox "File not found" & vbCrLf & myFile, vbExclamation
    Exit Sub
End If
Call FileTimeToLocalFileTime(wfd.ftCreationTime, ft)
Call FileTimeToSystemTime(ft, st)
Call FindClose(hFile)
Debug.Print st.wMonth & "/" & st.wDay & "/" & st.wYear & _
    " " & st.wHour & ":" & st.wMinute & ":" & st.wSecond
0
bemsonAuthor Commented:
the following sub or function is not defined, is it in an API, If so what is API & IN WHICH DLL

Call FileTimeToLocalFileTime
0
bemsonAuthor Commented:
the following sub or function is not defined, is it in an API, If so what is API & IN WHICH DLL

Call FileTimeToLocalFileTime
0
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

bemsonAuthor Commented:
the following sub or function is not defined, is it in an API, If so what is API & IN WHICH DLL

Call FileTimeToLocalFileTime
0
VbmasterCommented:
Declare Function FileTimeToLocalFileTime Lib "kernel32" Alias "FileTimeToLocalFileTime" (lpFileTime As FILETIME, lpLocalFileTime As FILETIME) As Long
0
bemsonAuthor Commented:
Debug.print statement for date shows system date not file date.
0
bemsonAuthor Commented:
Using a different file to that used in comments above I get:

Application run at 14:00:12 11-23-1999

VB FileDateTime = 25/11/98 11:51:44

Results are:

12/23/1998 9:27:36
0
Erick37Commented:
Running the code sample I posted, these are my results(Win 98, VB5):

File: autoexec.bat

Win Explorer date: 11/6/99 5:21 PM

ftCreationTime: 11/6/1999 17:21:14
ftLastAccessTime: 11/22/1999 0:0:0
ftLastWriteTime: 11/6/1999 17:21:16
The above data seems correct and reasonable.

Documentation on the WIN32_FIND_DATA structure says:
ftLastAccessTime:
Specifies a FILETIME structure containing the time that the file was last accessed. The time is in UTC format; the FILETIME members are zero if the file system does not support this time member.

ftLastWriteTime:
Specifies a FILETIME structure containing the time that the file was last written to. The time is in UTC format; the FILETIME members are zero if the file system does not support this time member.

--------------------------
I am uncertain as to the correlation between your results.
VB FileDateTime = 25/11/98 11:51:44 << How is this derived?

Results are:
12/23/1998 9:27:36 << Is this the creation time?
--------------------------
0
AnswerTheManCommented:
have not read all comments since i had same problem a year ago.
what i did was creating a managment application that throught there - the system manager can set values regarding KNOWN time difrencess between machins.
the DIFF is written to some registry key (can use a file if you want).
now, when the app runs - it looks to that registry key. if the DIFF there is, say, +2 hours - it treats +2 hours diffrence between files as same time, and act accordingly.
0
AnswerTheManCommented:
pS: the sys-manager can use this tool, on any occation he needs to update a change.
0
bemsonAuthor Commented:
To Erick37, vbmaster,AnswerTheMan, thank you for your comments & support.


The app loops twice reading each file in turn, the results are:

**************************************
Application run at 09:06:18 11-24-1999


Using VB5 FileDateTime(myFile), Results are:
VB FileDateTime = for Notebook WIN 95 = 25/11/98 10:51:44

Using API & Structures, results are:

11/24/1999 7:36:54

Using VB5 FileDateTime(myFile), Results are:
VB FileDateTime = for Desktop Win NT = 25/11/98 11:51:44

Using API & Structures, results are:

11/24/1999 8:48:39

** note the file is reported by VB5, one hour out on the NT desktop

***************************************


The following is my code for this app, Basically I have one file
on my notebook(Win95) & the same file on my desktop(WinNT)
 
can anybody see any obvious error in the code?

Public Type FILETIME
        dwLowDateTime As Long
        dwHighDateTime As Long
End Type

Public 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

Public Type WIN32_FIND_DATA
        dwFileAttributes As Long
        ftCreationTime As FILETIME
        ftLastAccessTime As FILETIME
        ftLastWriteTime As FILETIME
        nFileSizeHigh As Long
        nFileSizeLow As Long
        dwReserved0 As Long
        dwReserved1 As Long
        cFileName As String * 260
        cAlternate As String * 14
End Type

Public Declare Function FindFirstFile Lib "kernel32" Alias "FindFirstFileA" (ByVal lpFileName As String, lpFindFileData As WIN32_FIND_DATA) As Long
Public Declare Function FindClose Lib "kernel32" (ByVal hFindFile As Long) As Long
Public Declare Function FileTimeToSystemTime Lib "kernel32" (lpFileTime As FILETIME, lpSystemTime As SYSTEMTIME) As Long
Declare Function FileTimeToLocalFileTime Lib "kernel32" (lpFileTime As FILETIME, lpLocalFileTime As FILETIME) As Long
Private Sub Form_Load()

Dim wfd As WIN32_FIND_DATA
Dim ft As FILETIME
Dim st As SYSTEMTIME
Dim hFile As Long
Dim myFile As String

Dim x%
Dim FileSource$
   
    Debug.Print
    Debug.Print "Application run at "; Time$, Date$
    Debug.Print
   
    For x = 1 To 2
   
        If x = 1 Then
            myFile = "A:\notebook\416api.bas"
            FileSource = "Notebook WIN 95"
        Else
            myFile = "a:\WinNT\416api.bas"
            FileSource = "Desktop Win NT"
        End If

        hFile = FindFirstFile(myFile, wfd)
        If hFile = -1 Then
            MsgBox "File not found" & vbCrLf & myFile, vbExclamation
            Exit Sub
        End If
       
        Call FileTimeToLocalFileTime(wfd.ftCreationTime, ft)
        Call FileTimeToSystemTime(ft, st)
        Call FindClose(hFile)
             
    ' Output results to debug.print
        Debug.Print
        Debug.Print "Using VB5 FileDateTime(myFile), Results are:"
        Debug.Print "VB FileDateTime = for "; FileSource; " = "; FileDateTime(myFile)
        Debug.Print
        Debug.Print "Using API & Structures, results are:"
        Debug.Print
        Debug.Print st.wMonth & "/" & st.wDay & "/" & st.wYear & _
            " " & st.wHour & ":" & st.wMinute & ":" & st.wSecond
     
    Next x
 

End Sub

Thanks for your interest in my Problem.
0
bemsonAuthor Commented:
To all who have an interest in this problem!

I think I may have a partial answer why results are not true.

The files I create today using word or vb give the right answers.

The files I have problems with were originally created on 16 bit win 3.1.

I have just created a file today on 3.1 & results are incorrect.

Also it appears that when I update 16bit vb projects on NT there is a problem also.

Bottom line so far:
Files created on 32 bit system report ok

files created on 16 bit, not ok
files created on 16 bit & updated today on NT (USING 16 BIT VB), NOT OK

This occurs because I am still updating 16bit & 32 bit projects on NT.

My comparison program compares both 16 & 32 bit files, therefore the:

Type WIN32_FIND-DATA structure appears to have problems reading a file created by 16 bit.

Any comments please
0
Erick37Commented:
I viewed some old Win 3.11 files using Win 95 Explorer and found that the Creation date is reported as "unknown." However, the Modified date is correct.

Using
Call FileTimeToLocalFileTime(wfd.ftLastWriteTime, ft)
returns the same time reported in Win Explorer (which is correct on my system).

Using wfd.ftCreationTime returns "1/1/1601 1188:2:47" for the older DOS and Win 3.11 files (in other words, not supported).
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
bemsonAuthor Commented:
Thanks for you help

nb as well as dos files not supported, by having the 'automatic adjust for daylight saving' set in date/time/timezone, this will alter file times by one hour. Obviously a Windows system bug
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.