| | |
how to set file access time
![]() |
•
•
Join Date: Jan 2005
Posts: 16
Reputation:
Solved Threads: 0
Here the code where I'm trying to set last-accessed attribute of the file to some value.
I suppose I didn't set the correct attributes in CreateFile function.
Does anybody knows how to do this correctly?
C Syntax (Toggle Plain Text)
hFile = CreateFile(szDestName.GetBuffer(255), GENERIC_WRITE | GENERIC_READ, FILE_SHARE_WRITE | FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, 0); GetFileTime(hFile,&createTime,&accessTime,&writeTime); writeTime.dwHighDateTime -= 1000L; accessTime = writeTime; SetFileTime(hFile,&createTime,&accessTime,&writeTime); // at this point access and write(modified) times are equal CloseHandle(hFile); // at this point access time is changed to the current system time
I suppose I didn't set the correct attributes in CreateFile function.
Does anybody knows how to do this correctly?
Last edited by Dave Sinkula; Aug 20th, 2005 at 3:40 pm. Reason: Added [code][/code] tags.
you can't control the time because, as you found out, the os will change it when the file is closed.
•
•
•
•
Originally Posted by MSDN
Not all file systems can record creation and last access time and not all file systems
record them in the same manner. For example, on Windows NT FAT, create time has a
resolution of 10 milliseconds, write time has a resolution of 2 seconds, and access time
has a resolution of 1 day (really, the access date). On NTFS, access time has a
resolution of 1 hour. Therefore, the GetFileTime function may not return the same file
time information set using SetFileTime. Furthermore, FAT records times on disk in local
time. However, NTFS records times on disk in UTC, so it is not affected by changes in
time zone or daylight saving time.
•
•
Join Date: Jan 2005
Posts: 16
Reputation:
Solved Threads: 0
I found out that if you use:
CreateFile(szDestName.GetBuffer(255), 0, FILE_SHARE_WRITE | FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, 0);
instead of:
CreateFile(szDestName.GetBuffer(255), GENERIC_READ | GENERIC_WRITE, FILE_SHARE_WRITE | FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, 0);
then you can't read or write to the file obviously BUT:
you can check for the file existence without changing
it's access time, which was good enough in my case.
Thanks for your reply anyway.
CreateFile(szDestName.GetBuffer(255), 0, FILE_SHARE_WRITE | FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, 0);
instead of:
CreateFile(szDestName.GetBuffer(255), GENERIC_READ | GENERIC_WRITE, FILE_SHARE_WRITE | FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, 0);
then you can't read or write to the file obviously BUT:
you can check for the file existence without changing
it's access time, which was good enough in my case.
Thanks for your reply anyway.
![]() |
Similar Threads
- File Modification Time (Python)
- Long file load time, right click takes forever (Windows NT / 2000 / XP)
- ow can i access Time from Server (Visual Basic 4 / 5 / 6)
- Random shared file access details....... (Visual Basic 4 / 5 / 6)
- How to Get Last Accessed/Created/Modified File Date and Time (C)
- how willl i be able to save a specific record into my database file in ms access (Java)
Other Threads in the C Forum
- Previous Thread: Pointers and Dynamic Arrays
- Next Thread: Days Since a Given Date
| Thread Tools | Search this Thread |
#include adobe api array arrays asterisks binarysearch calculate char cm copyanyfile copyimagefile copypdffile cprogramme creafecopyofanytypeoffileinc createcopyoffile createprocess() csyntax database directory dynamic feet fflush fgets file fork forloop frequency getlasterror givemetehcodez global graphics gtkgcurlcompiling hacking hardware highest homework i/o include incrementoperators input interest kernel kilometer km linked linkedlist linux linuxsegmentationfault list locate logical_drives loopinsideloop. match matrix meter microsoft motherboard mqqueue mysql number odf open openwebfoundation owf pattern pdf performance pointer posix probleminc process program programming pyramidusingturboccodes radix read recursion recv repetition research scanf scheduling segmentationfault send sequential shape socket socketprograming stack standard string systemcall turboc unix user voidmain() wab win32api windows.h






