OK, So I took the code you posted, dropped into a button click event on a
brand new form, and... it didn't compile.
After a quick touch-up, I compiled it and it ran... and no error. The
LastAccessTime property worked properly and did not return today's date on
every file.
I do not doubt that you are getting the error you say you are. However, I
suspect that if you look more carefully at your code, you are accessing the
file before you call LastAccessTime, and that your own code is resetting the
access date.
Anyway, here is the code that works, and my notes:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim MyDir As New DirectoryInfo("C:\Downloads")
Dim Dt As Date
For Each File1 As FileInfo In MyDir.GetFiles
Dt = File1.LastAccessTime
MessageBox.Show("File: " + File1.Name + " Last Access " +
Dt.ToString())
Next
End Sub
Notes:
There is no GetLastAccessTime method on the FileInfo class. I assume that
you meant to use the LastAccessTime property.
You cannot use the variable name File in your For Each stmt because that is
also the name of a static class. If you use File1, you don't get an error.
--
--- Nick Malik [Microsoft]
MCSD, CFPS, Certified Scrummaster
http://blogs.msdn.com/nickmalik
Disclaimer: Opinions expressed in this forum are my own, and not
representative of my employer.
I do not answer questions on behalf of my employer. I'm just a
programmer helping programmers.