mirror of
https://github.com/fleschutz/PowerShell.git
synced 2025-05-15 21:14:53 +02:00
Added new-text-file.ps1
This commit is contained in:
parent
1962759708
commit
b4997ff74b
@ -1,7 +1,7 @@
|
||||
Your Headline
|
||||
============
|
||||
=============
|
||||
|
||||
Some introductory words...
|
||||
|
||||
- Point 1
|
||||
- Point 2
|
||||
1. Do this...
|
||||
2. Do that...
|
||||
|
7
data/templates/Text.txt
Normal file
7
data/templates/Text.txt
Normal file
@ -0,0 +1,7 @@
|
||||
Your Headline
|
||||
=============
|
||||
|
||||
Some introductory words...
|
||||
|
||||
1. Do this...
|
||||
2. Do that...
|
31
scripts/new-text-file.ps1
Normal file
31
scripts/new-text-file.ps1
Normal file
@ -0,0 +1,31 @@
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Creates a new text file
|
||||
.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
|
||||
.EXAMPLE
|
||||
PS> ./new-text-file.ps1 README.txt
|
||||
✅ New text file 'README.txt' created from template 'Text.txt'.
|
||||
.LINK
|
||||
https://github.com/fleschutz/PowerShell
|
||||
.NOTES
|
||||
Author: Markus Fleschutz | License: CC0
|
||||
#>
|
||||
|
||||
param([string]$path = "")
|
||||
|
||||
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'."
|
||||
exit 0 # success
|
||||
} catch {
|
||||
"⚠️ Error: $($Error[0])"
|
||||
exit 1
|
||||
}
|
Loading…
Reference in New Issue
Block a user