Updated new-markdown-file.ps1 and new-text-file.ps1

This commit is contained in:
Markus Fleschutz 2025-05-18 11:15:42 +02:00
parent 5e2b19c7f3
commit 4027d6149d
2 changed files with 10 additions and 14 deletions

View File

@ -4,26 +4,24 @@
.DESCRIPTION
This PowerShell script creates a new Markdown file from template file at: ../data/templates/Markdown.md.
.PARAMETER path
Specifies the path and new filename
Specifies the path and new filename (README.md by default)
.EXAMPLE
PS> ./new-markdown-file.ps1 letter.md
New Markdown file 'letter.md' created from template 'Markdown.md'.
PS> ./new-markdown-file.ps1
New file 'README.md' created from template 'Markdown.md'.
.LINK
https://github.com/fleschutz/PowerShell
.NOTES
Author: Markus Fleschutz | License: CC0
#>
param([string]$path = "")
param([string]$path = "README.md")
try {
if ($path -eq "" ) { $path = Read-Host "Enter the new filename" }
$pathToTemplate = Resolve-Path "$PSScriptRoot/../data/templates/Markdown.md"
Copy-Item $pathToTemplate "$path"
if ($lastExitCode -ne 0) { throw "Can't copy template to: $path" }
"✅ New Markdown file '$path' created from template 'Markdown.md'."
"✅ New file '$path' created from template 'Markdown.md'."
exit 0 # success
} catch {
"⚠️ Error: $($Error[0])"

View File

@ -4,26 +4,24 @@
.DESCRIPTION
This PowerShell script creates a new .txt file from template file at: ../data/templates/Text.txt.
.PARAMETER path
Specifies the path and new filename
Specifies the path and new filename (README.txt by default)
.EXAMPLE
PS> ./new-text-file.ps1 README.txt
New text file 'README.txt' created from template 'Text.txt'.
PS> ./new-text-file.ps1
New file 'README.txt' created from template 'Text.txt'.
.LINK
https://github.com/fleschutz/PowerShell
.NOTES
Author: Markus Fleschutz | License: CC0
#>
param([string]$path = "")
param([string]$path = "README.txt")
try {
if ($path -eq "" ) { $path = Read-Host "Enter the new filename" }
$pathToTemplate = Resolve-Path "$PSScriptRoot/../data/templates/Text.txt"
Copy-Item $pathToTemplate "$path"
if ($lastExitCode -ne 0) { throw "Can't copy template to: $path" }
"✅ New text file '$path' created from template 'Text.txt'."
"✅ New file '$path' created from template 'Text.txt'."
exit 0 # success
} catch {
"⚠️ Error: $($Error[0])"