Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

What do you use when you want to update the date-modified field of a file on Windows?

  1. commands accessible via C++, .NET, C#, or something native to Windows (Vista preferably)
  2. tools/applications preferably free, and if possible open source as well

Edit: there is already a page for applications as pointed out by CheapScotsman here.

If anyone knows how I can do this via C++, C#, WSH or something similar, well and good, else I would think everything else is covered in the linked question.

share|improve this question
add comment

migrated from stackoverflow.com Jul 21 '09 at 23:26

This question came from our site for professional and enthusiast programmers.

9 Answers

up vote 5 down vote accepted

If you feel like coding it yourself, .NET offers the File.SetLastAccessTime, File.SetCreationTime and File.SetLastWriteTime methods.

share|improve this answer
    
As good as it gets. Thanks. –  facepalmd Jul 22 '09 at 19:44
add comment

Here's a simple regfile I wrote to add right-click "touch" in Windows explorer. It'd be easy to script it, too, since it just calls:

cmd.exe /c copy %1+nul %1 /by
share|improve this answer
1  
Useful and handy too. Thanks. –  facepalmd Jul 21 '09 at 22:12
    
And don't forget copy nul some_file to create an empty file (which is what I see touch most often used for). –  Joey Aug 27 '09 at 6:28
    
Ack! Zip file inaccessible (something about brinkster22.com needing to be the referring site). Jon, can you update this? –  Dan7119 Mar 28 '11 at 14:22
add comment

You could also install Cygwin which gives you Touch as well as a plethora of other *NIX commands.

share|improve this answer
2  
can't live on windows without cygwin. –  jweede Sep 10 '09 at 12:32
    
And cygwin without mintty is pretty lame. –  Ahe Jan 25 '10 at 14:30
add comment

There are Windows ports of many Unix utilities. Have a look at unxutils or GnuWin32 projects.

share|improve this answer
add comment

From a similar question on Stack Overflow.

For updating timestamps (ignoring the other functionality of touch), I'd go with:

copy /b filename.ext +,,
share|improve this answer
    
Thank You.This was useful +1 :) –  Pavitar Apr 25 '11 at 14:26
add comment

How about codeproject "Touch for Windows": http://www.codeproject.com/KB/applications/touch_win.aspx

edit; Same question as here: http://stackoverflow.com/questions/51435/windows-version-of-the-unix-touch-command/51439

share|improve this answer
    
Thanks. I missed that in my search which resulted in loads of touch screen phone related stuff. Probably needs a better tag label I guess. –  facepalmd Jul 21 '09 at 21:52
add comment

Save the following as touch.bat in your %windir%\system32 folder or add the folder in which it is saved to your PATH environment variable:

@echo off
if %1.==. goto end
if not exist %1 goto end
copy /b %1 +,, > nul
echo %1 touched!
:end

Sample usage:

touch *.cpp
touch somefile.c

Reference: Microsoft KB 69581

share|improve this answer
    
Excellent! No external stuff, just copy. And of course most of us need it as a batch stript:) –  Bogdan Gavril Mar 27 '13 at 22:07
add comment

There is an utility which adds touch to the context menu (right-click) of a folder. More information is available here

share|improve this answer
add comment

The four alternatives mentioned above, plus four more not mentioned here, can be found in the answer to a similar question: "Windows Recursive Touch Command"

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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