Created
April 22, 2015 13:04
-
-
Save andineck/2f0784726086fb352c5c to your computer and use it in GitHub Desktop.
powershell read write file
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
$filePath = "test.txt" | |
# write append to file | |
echo 'halloo' >> $filePath | |
# write empty file | |
echo $null > $filePath | |
# read file into variable | |
$content = ""; | |
try { | |
$content = [IO.File]::ReadAllText($filePath) | |
} catch [System.Exception] { | |
Write-Host "File missing" | |
} | |
$content.Length | |
if ( $content.Length ) { Write-Host "not empty" } | |
# delete file | |
rm $filePath | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment