#OpenFile API
5 messages in this thread
Costas,
A field in the OFSTRUCT data type returned by the OpenFile function is a
4 byte field named "reserved". In Petzold's book, he says this field is
used with the OF_READ flag to compare a file's date/time. Does this mean
that it might be possible to somehow use this field to get a file's
date/time? Redefining it as a single and using it with format$ seems to
always return 12/30/99 12:00pm no matter what the value. Could this just be
a long with the number of seconds since some date?
BTW, OpenFile when used with the OF_EXIST flag is a great way to test for
a file's existence! In FM, I can read the font master file and test each
font's files for existence extremely quickly. It reads the master file and
tests 197 pfm files for existence in right at 1 second! Makes it real nice
to insure new entries in win.ini and atm.ini are for files that truly
exist. Also makes creating a VB FileExist function super simple.
Function FileExist (filename$) as integer
dim oFdat as OFSTRUCT
e = OpenFile(filename$, oFdat, OF_EXIST)
if e = -1 then
FileExist = false
else
FileExist = true
end if End Function
–dennis
There are 2 Replies.
Dennis you're brilliant! It does return the file date and probably file
time but you need to change the declare to test it.
Type OFSTRUCT
cBytes As String * 1
fFixedDisk As String * 1
nErrCode As Integer
r1 As Integer
r2 As Integer
szPathName As String * 128
End Type
Sub TestMe()
Dim a As OFSTRUCT
x% = OpenFile(SomeExistingFile$, a, of_exist) 'Supply filename
FileMonth% = ((a.r1 And &H7FFF) \ 32) And &HF
FileDay% = a.r1 And &H1F
FileYear% = (a.r1 And &H7FFF) \ 512 + 80
End Sub
r2 probably returns the time. Now, who said VB couldn't fancy things? <g>
Costas
P.S. Nelson if you're reading this – this should go into VBTIPS
There is 1 Reply.
Costas,
AHA! What a team! I thought it looked like there was something there, but I
was changing the reserved field to a single and never tried the 2 integers.
Even if I had, I'd have never guess how to decode it anyway! How in the
world did you figure that out?!
–dennis
There is 1 Reply.
Dennis,
It's funny, as I was reading your message when I got to the date and time
part it struck a chord and I remembered the good old CALL INTERRUPT days.
So, I dug out the code, tried it and it worked.
Costas
Dennis,
Yes, r2 holds the time so that can be unpacked as well:
FileHour% = (a.r2 And &H7FFF) \ 2048
If a.r2 < 0 Then FileHour% = (FileHour% + 16) – 12 'for PM times
FileMinute% = ((a.r2 And &H7FFF) \ 32) And &H3F
FileSecond% = (a.r2 And &H1F) * 2
Costas