You are not logged in. You can browse in the PowerBASIC Community, but you must click Login (top right) before you can post. If this is your first visit, check out the FAQ or Sign Up.
There is nothing wrong with using PB's QUAD variables to do that, and if you do that, you will instantly have the information you need. But you would have to explicitly use BYVAL VARTPTR with the QUAD variables, because of the PB prototype in WIN32API.
In re (it's been a long time since I had to look up the prototype, so this could be worng):
Yes, I saw that. But the actual PB call was not stated.
This is what I have, maybe if someone can help clarify the variables....
Declare Function CompareFileTime Lib "kernel32" ( _
lpFileTime1 As FILETIME, _
lpFileTime2 As FILETIME _
) As Long
What do I put in lpFileTime1 and lpFileTime2 ?
And what is FILETIME ?
This result should be:
-1 lpFileTime1 is smaller than lpFileTime2
0 lpFileTime1 is equal to lpFileTime2
+1 lpFileTime1 is larger than lpFileTime2
I just don't know what I shoulld be using for the variables?
A FILETIME is a 64bit TYPE containing the date and time in 100nSec units
since 1 Jan 1601 (UTC). Can be used for calculations and comparisions
on Dates/Times other than files.
What you put lpFileTime1 and lpFileTime2 is one of three times
associated with a file (see example code).
Code:
#include "Win32API.inc"
function CompFileTimes(FileName1 as string, FileName2 as string) as long
local nFile1, nFile2 as dword 'PB file number
local hFile1, hFile2 as dword 'Windows handle for file
local ErrNum as long
local FT1_Create, FT1_LastAccess, FT1_LastWrite as FileTime
local FT2_Create, FT1_LastAccess, FT1_LastWrite as FileTime
nFile1 = freefile
open FileName1 for binary as #nFile1 'can be "for input", "for append,
'{error checking left out} '"for output" or "for random"
nFile2 = freefile
open FileName2 for binary as #nFile2
'{error checking left out}
hFile1 = fileattr(#nFile1, 2)
hFile2 = fileattr(#nFile2, 2)
ErrNum = GetFileTime hFile1, FT1_Create, FT1_LastAccess, _
FT1_LastWrite as FileTime
'{error checking left out}
ErrNum = GetFileTime hFile2, FT1_Create, FT2_LastAccess, _
FT2_LastWrite as FileTime
'{error checking left out}
function = CompareFileTime FT1_LastWrite, FT2_LastWrite
close
#if 0 '-----------logical equiv of CompareFileTime ------
if FT1_LastWrite > FT2_LastWrite then
function = 1
elseif FT1_LastWrite < FT2_LastWrite then
function = -1
else
function = 0
end if
#endif
end function
Have you looked msdn.microsoft.com ?
Last edited by Dale Yarker; 16 Nov 2009, 02:05 AM.
Reason: Added CLOSE to code
This is what I use to check to see if one file is new than another.
First, get the FILETIME of each file:
Code:
Local diskFILETIME1, diskFILETIME1 As FILETIME
Local sFilename1 As ASCIIZ * %MAX_PATH
Local sFilename2 As ASCIIZ * %MAX_PATH
...
...
...
DTSignature sFilename1, diskFILETIME1
DTSignature sFilename2, diskFILETIME2
Next, do the comparison:
If CompareFileTime( diskFILETIME1, diskFILETIME1 ) <> 0 Then
..
..
..
End If
Code:
'//
'// Determines the last update date/time of the specified file
'// The time stamp, as its raw FILETIME API value (64-bit) ; 0 on error
'// This function is purely to provide a way of telling when this value
'// changes for a file ; turning the value found into a human-readable
'// time is another matter altogether.
'//
Function DTSignature( ByRef zFileSpec As Asciiz, _
RETURN_FILETIME As FILETIME _
) Export As Long
Local hFile As Long
Local uFind As WIN32_FIND_DATA
'Locate the file...
hFile = FindFirstFile( zFileSpec, uFind )
If hFile Then
Return_FILETIME = uFind.ftLastWriteTime
FindClose hFile
End If
End Function
Paul Squires
FireFly Visual Designer (for PowerBASIC Windows 10+)
Version 3 now available. http://www.planetsquires.com
Dale & Paul,
Thank you. Your explanations have been most helpful. If you can indulge me and answer a couple additional questions.
Files have several dates: Date Created, Date modified, Date Accessed, and others. Which date do these routine use for making the comparison? I am hoping it's the date modified.
If one of the files on which the comparison is going to be made is downloaded first from the intenet, will that affect the date comparison?
Contains information about the file that is found by the FindFirstFile, FindFirstFileEx, or FindNextFile function. (ANSI)
If one of the files on which the comparison is going to be made is downloaded first from the intenet, will that affect the date comparison?
Not sure about an answer for that question. Not sure if the file date/time stamp gets modified when a file is downloaded. I guess the easiest way is to test it.
Paul Squires
FireFly Visual Designer (for PowerBASIC Windows 10+)
Version 3 now available. http://www.planetsquires.com
We process personal data about users of our site, through the use of cookies and other technologies, to deliver our services, and to analyze site activity. For additional details, refer to our Privacy Policy.
By clicking "I AGREE" below, you agree to our Privacy Policy and our personal data processing and cookie practices as described therein. You also acknowledge that this forum may be hosted outside your country and you consent to the collection, storage, and processing of your data in the country where this forum is hosted.
Comment