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

View File

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