Change file creation date

jkatshor

Member
Joined
Mar 20, 2009
Messages
11
Programming Experience
Beginner
Hello,
I'm trying to save a files save date, modify that file and then restore the file back to it's original date. I can't get it to work, I've tried it several ways and cannot get it to work.

My code so far is

VB.NET:
origdate = My.Computer.FileSystem.GetFileInfo("inspection").LastWriteTime.ToShortDateString()
' changing file content here

System.IO.File.SetLastAccessTime("inspection", origdate)
VB.NET:
 
Why call ToShortDateString? What does LastWriteTime return? A DateTime value. What does SetLastAccessTime expect as an argument? A DateTime value. So why the conversion to a String in between? If you get an egg from a chicken and you have a recipe that needs an egg, would you make an omelette in between?

Aprt from that, the last write time and the last access time are not the same thing. If you're getting the last write time then shouldn't you be setting the last write time too?

Finally, if you're going to use File.SetLastWriteTime to set the time then you should be consistent and use File.GetLastWriteTime to get it in the first place.
 
Back
Top