Click here to Skip to main content
15,904,416 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am curious and I haven't been able to find the answer by googling. What is the actual time of a files LastWriteTime? Is it when the file is first being written or is it when the file finishes being written? Thank you.
Posted

If memory serves the time is updated when the file is closed. This should be fairly easy to confirm with a few lines of code.
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 6-Nov-11 22:10pm    
Most likely, you are right; I voted 5 without this test as I would guess it would be quite logical; please see my comment to the answer by Chuck.
--SA
Richard MacCutchan 7-Nov-11 4:29am    
Thanks, I did not bother to test it myself as I thought that if OP really wanted the answer it is only a few lines of code.
According to the documentation for GetFileTime() [^] Windows records *both* the creation time *and* the time the file was last written to. Pick the one that's useful to you.
 
Share this answer
 
Comments
Member 7766180 6-Nov-11 16:45pm    
OK thats a good answer!
Sergey Alexandrovich Kryukov 6-Nov-11 22:09pm    
Chuck, this was not the question (I don't know why OP accepted this answer): GetFileTime returns three different times, not two, and the question was about lpLastTime only: what moment of time is recorded. I would guess Richard is right (see his answer) just because it looks logical: when a file is opened, the open time is recorded, and close time is recorded, too, then if modification did not happen, only the lpLastAccesstime is updated by the open time; if not -- both lpLastAccesstime and lpLastWriteTime times are updated from open and close time, respectively. After all, as Richard noted, it's easy to check up.
--SA
Chuck O'Toole 6-Nov-11 22:14pm    
Sorry I took a shortcut and removed extraneous information. The 3rd time, access time, is uninteresting with respect to the question about write times so I did not mention it.

The other thing, the questioner wanted to know if the write time was updated when the file was created or when it was done being written. Again, since both of those times are recorded, it makes no difference as you can determine either time by looking at the returned data.

And no disrespect to Richard but he stated he was doing this on memory only and suggested a test to confirm or deny his recollection. Hardly a definitive answer.
Richard MacCutchan 7-Nov-11 4:32am    
It wasn't meant to be definitive. My real point was that it would take even a novice programmer less than a couple of minutes to find out for themselves. And no disrespect to you but you answered a different question.
 
Share this answer
 
Comments
Member 7766180 6-Nov-11 16:17pm    
Mehdi I know how to get it. I need to know when is the last write time. When the write starts or when it ends?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900