Last active
December 6, 2019 00:36
-
-
Save belsrc/451921b27eadfa4479e1 to your computer and use it in GitHub Desktop.
touch command in Powershell
This file contains 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
# Type 'notepad $profile' to open your profile ps1 file and add | |
# This will add the file if it doesn't exist or update the | |
# last write time if it does | |
# If you get some message about not being able to run scripts then you need to type the following command and restart powershell | |
# Set-ExecutionPolicy Bypass | |
Function touch { | |
$file = $args[0] | |
if($file -eq $null) { | |
throw "No filename supplied" | |
} | |
if(Test-Path $file) { | |
(Get-ChildItem $file).LastWriteTime = Get-Date | |
} | |
else { | |
echo $null > $file | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
change that echo to
New-Item -force -type file $file
that will create the entire path for the file if it does not exist, and it will be 0 in length as well just remove -force if you don't want auto directory creation