• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 614
  • Last Modified:

File.SetLastWriteTime Not working as planned

Hi All,
I am trying to set the File.SetLastWriteTime with that of a file that it was copied from.
It kinda works.  Problem is that when getting the new GetLastWriteTime it is one or two seconds greater than the date/time provided.

For instance if the Source file is 01/28/2014 1:18 PM, the Destination file, that is being altered, shows a value of 01/28/2014 1:20 PM. It's as if the SetLastWriteTime is working but taking a couple seconds, so that a new value is set.

example: (TDest$ and TSource$ are files, including paths)
File.SetLastWriteTime(TDest$, File.GetLastWriteTime(TSource$))

Any ideas?
0
Thunder724
Asked:
Thunder724
  • 4
  • 3
  • 2
1 Solution
 
CodeCruiserCommented:
That is actually 2 minutes not seconds. Is there any other code between the setting the time and closing the file?
0
 
Thunder724Author Commented:
Oh, sorry.... My fault in the example. it is actually seconds not minutes; I forgot to add the minute part.  No there is nothing between the code at all, that's why its driving me insane.
0
 
CodeCruiserCommented:
Can you show your code?
0
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
Thunder724Author Commented:
sure, I put it in the original message.
But before that I am copying these files first.  
I even tried changing the SetLastWriteTime after the function that runs and contains the CopyFile function.

My.Computer.FileSystem.CopyFile(TSource$, TDest$, FileIO.UIOption.AllDialogs, FileIO.UICancelOption.ThrowException)

File.SetLastWriteTime(TDest$, File.GetLastWriteTime(TSource$))
0
 
CodeCruiserCommented:
If you do a

msgbox File.GetLastWriteTime(TSource$)

do you get the same datatime stamp as you see in explorer?
0
 
Thunder724Author Commented:
I can't explain it; but it looks to be working correctly now. I really didn't do anything either.
I will get back to you tomorrow to close this if everything is still testing out correctly.  
Thanks very much for you help.
0
 
ArkCommented:
Which file system was on TDest$?
According to http://www.xxcopy.com/xxcopy15.htm
For the compatibility's sake, even WinNT/2K
  uses the same 2-second granularity for the "Last-modified" time for
  FAT-based file system (does not apply for NTFS files).
0
 
Thunder724Author Commented:
NTFS.
it seems to be a specific issue only when syncing to/from a usb stick.
0
 
ArkCommented:
There is another issue with NTFS - it does store time stamps with 100 ns granularity but it UPDATES values only after 1 hour
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

  • 4
  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now