Possible Duplicate:
How to modify timestamp in a dll or exe?

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

My specific situation is Windows 7, and I'd prefer to use Sysinternals tools suite. A generic answer would do just fine, though.

link|improve this question
You should probably clarify your question and state that you want to choose the new timestamp. The two current answers assume you are looking for a Windows port of the Unix command touch that sets a files's timestamp to the current time. – William Jackson Jun 3 '11 at 20:44
I've looked through Sysinternals, and I'm pretty sure they don't have a utility for this. You should try the programs linked to from superuser.com/questions/135901/… – William Jackson Jun 3 '11 at 20:50
@William Jackson Changed, thanks for that. Also, if it truly was a port of the Unix command touch, I could specify the date. en.wikipedia.org/wiki/Touch_(Unix). Something is wrong with the auto linking though, make sure you get both parentheses. – josmh Jun 3 '11 at 20:50
I ... can't believe I never bothered to read man touch. You have taught me something new. – William Jackson Jun 3 '11 at 20:56
feedback

closed as exact duplicate by josmh, Randolph West, MaQleod, techie007, Sathya Jun 4 '11 at 6:11

This question covers exactly the same ground as earlier questions on this topic; its answers may be merged with another identical question. See the FAQ for guidance on how to improve it.

5 Answers

See the answers to this question:

http://stackoverflow.com/questions/51435/windows-version-of-the-unix-touch-command

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.

link|improve this answer
Can you explain how that is working? What is the +,,? How do I know what date it is being set to? – josmh Jun 3 '11 at 20:05
@josmh Check the documentation link for details. The timestamp gets set to the current time when you run the command. Are you implying that you want to be able to change the timestamp to an arbritary time of your choosing? – William Jackson Jun 3 '11 at 20:10
1  
I'm not seeing how that helps me choose a new date for the file? – josmh Jun 3 '11 at 20:42
feedback

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")
link|improve this answer
A slight variation that is recursive and a little shorter, though less readable: "gci -rec | %{ $_.lastWriteTime = ($_.lastAccessTime = ($_.creationTime = (get-date "2011-09-14T07:10:00"))) }" – it depends Sep 14 '11 at 6:36
feedback
up vote 1 down vote accepted

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

touch -t 200001310001.00 test.txt
link|improve this answer
feedback

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"

link|improve this answer
feedback

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.

link|improve this answer
feedback

Not the answer you're looking for? Browse other questions tagged or ask your own question.