Created
June 26, 2017 18:32
-
-
Save tmlbl/6bed0f1411ca99e7f8742166eaa1dfcb to your computer and use it in GitHub Desktop.
Unix 'touch' command for PowerShell
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function touch() { | |
<# | |
.SYNOPSIS | |
An analog to the UNIX 'touch' command | |
.DESCRIPTION | |
This approximates common usage of the UNIX 'touch' command. If the target | |
file does not exist, it is created as a regular file. If it does exist, the | |
last access time is set to the current time. | |
.PARAMETER fname | |
The target file path | |
#> | |
param ($fname) | |
If (Test-Path $fname) { | |
$(Get-Item $fname).LastAccessTime = $(Get-Date) | |
} Else { | |
New-Item -Type File -Name $fname | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment