New-TextFile
Creates a text file
param([string]$path = "README.txt")
try {
if (Test-Path "$path" -pathType leaf) { throw "File '$path' is already existing" }
$pathToTemplate = Resolve-Path "$PSScriptRoot/data/templates/New.txt"
Copy-Item $pathToTemplate "$path"
if ($lastExitCode -ne 0) { throw "Can't copy template to: $path" }
"? New '$path' created (from data/templates/New.txt)."
exit 0 # success
} catch {
"?? ERROR: $($Error[0]) (script line $($_.InvocationInfo.ScriptLineNumber))"
exit 1
}Specifies the path and new filename (README.txt by default)