Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

File.SetLastWriteTime Not working as planned

Posted on 2014-01-28
9
Medium Priority
?
581 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

 
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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…

609 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