skip to Main Content

Touching a File with PowerShell

I am finding more and more things I can do with PowerShell everyday. The other day, I had to “touch” a file… one line is what it takes:

(ls testFile.txt).LastWriteTime = New-object DateTime 1991,12,31

Chinh Do

I occasionally blog about programming (.NET, Node.js, Java, PowerShell, React, Angular, JavaScript, etc), gadgets, etc. Follow me on Twitter for tips on those same topics. You can also find me on GitHub.

See About for more info.

This Post Has 3 Comments
  1. Thanks for the tip, D. If we go with the standard definition of “touch” – to change the file modification time to the current time – then your version is definitely shorter. When I was doing this, I had a need to use a specific time.

Leave a Reply

Your email address will not be published. Required fields are marked *

Back To Top