103

Possible Duplicate:
How to modify timestamp in a dll or exe?
Windows equivalent of the Linux command 'touch'?

How can I set the timestamp for a file via the command-line to a specific date?

My specific situation is Windows 7.

5 Answers5

130

Due to William Jackson's answer, I found a similar question on Stack Overflow.

The accepted answer states to use Powershell and these commands:

$(Get-Item ).creationtime=$(Get-Date "mm/dd/yyyy hh:mm am/pm")
$(Get-Item ).lastaccesstime=$(Get-Date "mm/dd/yyyy hh:mm am/pm")
$(Get-Item ).lastwritetime=$(Get-Date "mm/dd/yyyy hh:mm am/pm")

Edit

Two examples:

(This one is from the comments:) Set the last-access time for a file aaa.csv to the current time:

$(Get-Item aaa.csv).lastwritetime=$(Get-Date)

Set the creation time of a file foo.txt to November 24, 2015, at 6:00am:

$(Get-Item foo.txt).creationtime=$(Get-Date "11/24/2015 06:00 am")
57

See the answers to this question.

Specifically, this can be done natively with:

copy /b filename.ext +,,

This will set the timestamp to the current time.

Documentation for the copy command is on TechNet.

The commas indicate the omission of the Destination parameter.

Uwe Keim
  • 2,112
26

Nirsoft to the rescue: try the freeware tool nircmd. It's a bunch of useful tools in one small command line program. One of the commands allows you to specify either or both of created time and modified time, like this:

nircmd.exe setfiletime "c:\temp\myfile.txt" "24-06-2003 17:57:11" "22-11-2005 10:21:56"

boot13
  • 5,917
23

Using Cygwin, to set the timestamp of test.txt to January 31, 2000, at 00:01.00:

touch -t 200001310001.00 test.txt
2

Check out the following webpage: http://www.stevemiller.net/apps/

The Win32 Console Toolbox contains a utility called 'touch' that lets you modify the times on one or more files. I believe it only works with US format times, though.