2

Where can I get the touch utility for Windows?

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

benPearce
  • 321
  • 5
  • 11

2 Answers2

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
}
Zypher
  • 37,405
  • 5
  • 53
  • 95
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.

nik
  • 7,100
  • 2
  • 25
  • 30
  • how does this copy command allow you to change the date time stamp – benPearce Jun 10 '09 at 02: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 '09 at 02:15
  • but that only allows you to set the timestamp to now – benPearce Jun 10 '09 at 02:47
  • Ah, you should use the Cygwin method with touch then -- it will be touch -t [[CC]]YY]MMDDhhmm[.ss]. – nik Jun 10 '09 at 03:11