0

Is there a Windows equivalent to the touch command?

Mokubai
  • 89,133
  • 25
  • 207
  • 233
Isaac
  • 45
  • 3
  • 3
    Hi and welcome to Superuser . While it's [OK - and encouraged - to Ask and Answer Your Own Questions](https://stackoverflow.blog/2011/07/01/its-ok-to-ask-and-answer-your-own-questions/?_ga=2.207180051.1051913068.1684039935-1108829733.1673436791), this site is a Q&A style site, so it'd be best to edit the question to put the situation/dilemma/question/problem there, and then put the solution as an answer. – Yisroel Tech May 17 '23 at 01:57
  • While you're at it, maybe give a couple of examples in the answer so people will know what format the timestamp uses. Or let people know if the timestamp format depends on your system settings. – RobH May 17 '23 at 02:20

1 Answers1

2

touch.ps1

Usage: touch [FILE]...


   param(
        [Parameter()]
        [String]$file
    )
    if(Test-Path -Path $file){
        (Get-Item -Path $file) | % {$_.LastWriteTime = (Get-Date)}
    }
    else{
        (New-Item $file)
    }

Add the directory to your touch.ps1 script to the PATH environment variable and you should be set.

Isaac
  • 45
  • 3