2

Where can I get the touch utility for Windows?

I have tried this one at CodeProject but it did not change directorys.

2 Answers 2

4

you can use powershell to do this as well. I have the following function in my $profile

function touch([string] $filename)
{
$curTime = Get-Date
$touchFile = get-item $filename
$touchFile.CreationTime = $curTime
$touchFile.LastAccessTime = $curTime
$touchFile.lastWriteTime = $curTime
}
1
  • I think that this could be extended to allow the date to be supplied
    – benPearce
    Jun 10, 2009 at 5:22
0

There are several solutions at https://stackoverflow.com/questions/51435/windows-version-of-the-unix-touch-command

While most of them suggest getting Cygwin (my bias too) or some other unix utilities, there is one answer describing a windows method.

copy /b filename.ext +,,

Another simple solution from the same answer is to get the Cygwin.dll and touch.exe copied locally in your windows system. It will work better if you want to process directories recursively.

4
  • how does this copy command allow you to change the date time stamp
    – benPearce
    Jun 10, 2009 at 2:11
  • The /b treats the file as binary and the +,, tell it to copy the file back to the same place effectively updating the timestamp. But, since you ask, i prefer the Cygwin, touch.exe method.
    – nik
    Jun 10, 2009 at 2:15
  • but that only allows you to set the timestamp to now
    – benPearce
    Jun 10, 2009 at 2:47
  • Ah, you should use the Cygwin method with touch then -- it will be touch -t [[CC]]YY]MMDDhhmm[.ss].
    – nik
    Jun 10, 2009 at 3:11

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .