Solved

File.SetLastWriteTime Not working as planned

Posted on 2014-01-28
9
542 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
MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

 
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 500 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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.

Question has a verified solution.

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

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

739 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