Last access date of a file


















These are perfectly normal situations; this is a performance optimisation by microsoft which has rendered GetLastWriteTime useless. Show 3 more comments. Create, FileAccess. Write, FileShare. AreNotEqual lastModified, File. GetLastWriteTime seems to be returning 'out of date' value Your options: a live with the occasional omissions. Create, fileAccess, FileShare. Open, FileAccess. Read, FileShare.

FromBinary reader. Write LastSignal. FilePath ; Assert. IsFalse fileSignal. CheckIfSignalled ; Assert. IsFalse fileSignal2. AreEqual fileSignal. LastSignal, fileSignal2. LastSignal ; fileSignal. Signal ; Assert. AreNotEqual fileSignal. LastSignal ; Assert. IsTrue fileSignal2. Community Bot 1 1 1 silver badge. Udontknow Udontknow 1, 12 12 silver badges 29 29 bronze badges. Note This is the fifth in a series of posts that talk about working with files and folders by using Windows PowerShell.

You should read the previous posts:. There are three basic properties of a file that I commonly use when looking at files that are neglected. The first is the date it was created, the second is when it was modified, and last is when it was accessed. These properties are visible when I to go the General tab of a file in File Explorer. An example of these values is shown here:. The command to do this is:. It is possible that a file may have been accessed, but the access did not modify the file.

It is also possible that a file may have been created, and then neither accessed or written to again. For my purpose today, I am going to use the LastWriteTime property. I want to create a simple function that I can use that permits me to supply an array of folders and a begin date.

The function is shown here:. In the first command line, I look for files that have not been accessed in 60 days:. Updating the atime every time a file is read causes a lot of usually-unnecessary IO, slowing everything down.

So, most Linux distributions now default to the noatime filesystem mount option, which basically kills atimes, or else relatime , which only updates atimes once a limit has passed normally once per day or if the file was actually modified since the previous read.

You can find if these options are active by running the mount command. Also, note that access times are by inode, not by filename, so if you have hardlinks, reading from one will update all names that refer to the same file.

And, in fact, many file editors work by making copies over the original. If you need that information, it's best to use a version control system like git. The find command is best for this. See the -ctime , -mtime , and -atime options. If your listing is for human consumption, use ls with one of the date sorting flags -tu for access read time, just -t for modification write time or -tc for inode change time.

See mattdm's answer for more information in particular the caveat regarding -a and the definition of -c. If this is for program consumption, parsing the output of ls is problematic.

A lowercase o sorts by increasing age. Otherwise, if you know that the file names don't contain any newline or non-printable characters in the current locale , then you can do something like. If you want to invoke a command on many files at once, you need more setup.

The following code works as long as no filename contains a newline or a non-printable character:. If you want to cope with arbitrary file names, you'll have a very hard time without resorting to more powerful tools than a standard shell: zsh, perl, python…. Sign up to join this community.

The best answers are voted up and rise to the top. I wrote a book Ground rules Disclaimers and such My necktie's Twitter. How do I access a file without updating its last-access time?

October 10th, Raymond Chen October 12,



0コメント

  • 1000 / 1000