473,385 Members | 1,869 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

How to get LastAccessTime of a file without modifying it?

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
2 2387
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Thomas Lotze | last post by:
Hi, another question: What's the most efficient way of copying data between two file-like objects? f1.write(f2.read()) doesn't seem to me as efficient as it might be, as a string containing...
10
by: Kenneth McDonald | last post by:
I could've sworn python had such a command, but now I can't find it... I'm looking for an easy way to perform a UNIX-style "touch", to update the modification time of a file without actually...
0
by: Bob | last post by:
If I access a file on a WinNT server, System.IO.File.GetLastAccessTime(FileName) doesn't return updated information for a few minutes. Is this a "feature" of NT or a symptom of disk caching? If I'm...
8
by: Inspector | last post by:
I'm hoping I might be able to pick someone's brain out there. Our company is currently running an inhouse application in which data is being stored in SQL. Included in this data are thousands...
1
by: A.M-SG | last post by:
Hi, Can I view/modify SOAP message at the client proxy side without using soap extensions? Thank you,
24
by: allpervasive | last post by:
hi all, this is reddy, a beginner to c lang,,here i have some problems in reading and modifying the contents of a file,, hope you can help to solve this problem. Here i attach the file to be...
1
by: Brian Simmons | last post by:
Hi All, I know that if you modify the web.config file or any file in the App_Code subfolder, that ASP.net 2.0 will "restart" the application (i.e. clear out any sessions, etc...). Are there...
0
by: Juan T. Llibre | last post by:
Here's the updated list of file changes which trigger Aplication restarts : 1. Adding, modifying, or deleting any source code file in any application folder ( *.cs, *.vb, etc. ) 2. Adding,...
5
by: Andrew Cooper | last post by:
I've got an application that I'm modifying and the client needs it to watch a particular file and then do some stuff when that file gets modified. For example, let's say the file is C:\Test.dat...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.