Last Accessed file attribute
Posted on 2002-06-25
I've been tring to modify the last accessed file attribute on about 400,000 files.
The API reference includes SetFileTime - which looked good.
Searching the web for examples I found many, all using this call in the same way:
hFile = OpenFile (fName,...
SetFileTime hFile, newCreateTime, newAccessTime, newModifyTime
Which only kinda works - I've modified the above to add msgboxes to follow progress, and what happens is that the SetFileTime can actually change the Last Accessed attribute, but the CloseFile "touches" the file and sets the Last Accessed attribute to the current system time.
The only way I've been able to acheive what I want is nasty - I change the system time, open the file, close the file, reset the system time.
Someone has suggested using FindFirstFile to get a handle to pass to SetFileTime, but I can't get this to work.
Anyone able to help me with this?
The best I've got so far is:
Private Sub Command1_Click()
Dim hFile As Long
Dim fName As String
Dim OFS As OFSTRUCT
Dim FT_CREATE As FILETIME
Dim FT_ACCESS As FILETIME
Dim FT_WRITE As FILETIME
'assign the textbox entry to the filename
fName = Text1
'open the file
hFile = OpenFile(fName, OFS, OF_READWRITE)
'get the FILETIME info for the created, accessed and last write info
Call GetFileTime(hFile, FT_CREATE, FT_ACCESS, FT_WRITE)
'set all times to last write time
Call SetFileTime(hFile, FT_WRITE, FT_WRITE, FT_WRITE)
'clean up by closing the file