Chinh Do

Touching a File with PowerShell

25th June 2008

Touching a File with PowerShell

posted in PowerShell, Programming |

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
This entry was posted on Wednesday, June 25th, 2008 at 9:48 pm and is filed under PowerShell, Programming. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

There are currently 2 responses to “Touching a File with PowerShell”

  1. 1 On May 26th, 2011, D said:

    (ls testFile.txt).LastWriteTime = Get-Date

  2. 2 On May 26th, 2011, Chinh Do said:

    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 Comment