I have a list of sales orders in a folder. I want a batch script that can output into a txt file, when were all the files last accessed but not necessarily modified.
On partitions with NTFS file system there are 3 file dates: creation date, last modification date and last access date.
The command
dir "path to directory" /TA /OD
lists all files of the directory according to last access date with last accessed file at bottom.
dir "path to directory" /TA /O-D
list the files in reverse order with last accessed file at top.
It is of course possible to redirect the output into a file by appending >"Name of list file with path.log"
But don't trust the last access time too much as it is really not reliable on when a file was last time opened for read only.
For more parameters of command dir
open a command prompt window and enter dir /?
As others have said, Last Access Date is not reliable on NTFS. But if you wanted to extract it anyway, here is one way, but it will need a bit more parsing:
wmic DataFile where "Name='C:\\Users\\Default\\NTUSER.DAT'" get LastAccessed /value
Last Access has been turned off by default for many years.
This command shows the setting of any computer you are interested in.
fsutil behavior query disablelastaccess
For using lastaccess - programs that don't open a file under user direction (eg search indexers, icon extractors like explorer, property sheets, etc) have to go back and restore last access to what it was before they opened it.