user391986
user391986

Reputation: 30906

batch script reset the timestamp on all files

In Windows 7, how can I clear or set to today the timestamp of all files and subfiles in a specific directory? I already disabled the timestamp saving using fsutil behavior set disablelastaccess 1, but to this point it has been saved. How could I clear that?

Upvotes: 0

Views: 2651

Answers (1)

dbenham
dbenham

Reputation: 130839

It is screwy syntax, but copy file+ will update the last written attribute of file without making any changes to the content. The file must be in the current directory.

The above works in Vista. I've also seen copy file+,, instead. This also works in Vista, and perhaps this form is required in some other versions of Windows.

I'm not sure what you mean when you say that you "disabled the timestamp saving using fsutil behavior set disablelastaccess 1". The last written timestamp will still be updated whenever the file is changed. The only thing that is disabled is the update of the last access timestamp. This is the default behavior from Vista forward. The last access timestamp is worthless anyway because Windows does not reliably set it upon access.

You can easily update the last written timestamp for all files in a directory and subdirs using the following script.

@echo off
setlocal
for /d /r "someDirectoryPath" %%D in (.) do (
  cd "%%D"
  copy *+
)

Upvotes: 3

Related Questions