By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,255 Members | 2,575 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,255 IT Pros & Developers. It's quick & easy.

How to get LastAccessTime of a file without modifying it?

P: n/a
Hi,

i am reading the LastAccessTime, LastWriteTime and DateofCreation of a file.
The second and third are working well, but each time i want to read the
LastAccessTime, its set to "now". How can i read the LastAccessTime of a file
without modifying it?

thanks
Yavuz Bogazci
Nov 21 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
post code, please.

--
--- 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.
--
"Yavuz Bogazci" <Ya**********@discussions.microsoft.com> wrote in message
news:28**********************************@microsof t.com...
Hi,

i am reading the LastAccessTime, LastWriteTime and DateofCreation of a file. The second and third are working well, but each time i want to read the
LastAccessTime, its set to "now". How can i read the LastAccessTime of a file without modifying it?

thanks
Yavuz Bogazci

Nov 21 '05 #2

P: n/a
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.
--
"Yavuz Bogazci" <Ya**********@discussions.microsoft.com> wrote in message
news:43**********************************@microsof t.com...
Here is my Code:

Dim MyDir As New DirectoryInfo(Dir)

For Each File As FileInfo In MyDir.GetFiles
file.GetLastAccessTime
Next

Not more.

Thanks
Yavuz Bogazci

"Nick Malik [Microsoft]" wrote:
post code, please.

--
--- 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.
--
"Yavuz Bogazci" <Ya**********@discussions.microsoft.com> wrote in message news:28**********************************@microsof t.com...
Hi,

i am reading the LastAccessTime, LastWriteTime and DateofCreation of a

file.
The second and third are working well, but each time i want to read the LastAccessTime, its set to "now". How can i read the LastAccessTime of
a file
without modifying it?

thanks
Yavuz Bogazci


Nov 21 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.