?
Solved

File.SetLastWriteTime Not working as planned

Posted on 2014-01-28
9
Medium Priority
?
566 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
Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

 
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

Independent Software Vendors: 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!

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
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

762 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