?
Solved

File.SetLastWriteTime Not working as planned

Posted on 2014-01-28
9
Medium Priority
?
592 Views
Last Modified: 2014-02-21
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
Comment
Question by:Thunder724
  • 4
  • 3
  • 2
9 Comments
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 39816487
That is actually 2 minutes not seconds. Is there any other code between the setting the time and closing the file?
0
 
LVL 4

Author Comment

by:Thunder724
ID: 39816535
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
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 39816542
Can you show your code?
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 4

Author Comment

by:Thunder724
ID: 39816551
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
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 39817332
If you do a

msgbox File.GetLastWriteTime(TSource$)

do you get the same datatime stamp as you see in explorer?
0
 
LVL 4

Author Comment

by:Thunder724
ID: 39818185
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
 
LVL 28

Expert Comment

by:Ark
ID: 39820141
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
 
LVL 4

Author Comment

by:Thunder724
ID: 39825273
NTFS.
it seems to be a specific issue only when syncing to/from a usb stick.
0
 
LVL 28

Accepted Solution

by:
Ark earned 2000 total points
ID: 39825782
There is another issue with NTFS - it does store time stamps with 100 ns granularity but it UPDATES values only after 1 hour
0

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
Suggested Courses

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question