Skip to content

Commit b4997ff

Browse files
author
Markus Fleschutz
committed
Added new-text-file.ps1
1 parent 1962759 commit b4997ff

File tree

3 files changed

+41
-3
lines changed

3 files changed

+41
-3
lines changed

data/templates/Markdown.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Your Headline
2-
============
2+
=============
33

44
Some introductory words...
55

6-
- Point 1
7-
- Point 2
6+
1. Do this...
7+
2. Do that...

data/templates/Text.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Your Headline
2+
=============
3+
4+
Some introductory words...
5+
6+
1. Do this...
7+
2. Do that...

scripts/new-text-file.ps1

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<#
2+
.SYNOPSIS
3+
Creates a new text file
4+
.DESCRIPTION
5+
This PowerShell script creates a new .txt file from template file at: ../data/templates/Text.txt.
6+
.PARAMETER path
7+
Specifies the path and new filename
8+
.EXAMPLE
9+
PS> ./new-text-file.ps1 README.txt
10+
✅ New text file 'README.txt' created from template 'Text.txt'.
11+
.LINK
12+
https://github.com/fleschutz/PowerShell
13+
.NOTES
14+
Author: Markus Fleschutz | License: CC0
15+
#>
16+
17+
param([string]$path = "")
18+
19+
try {
20+
if ($path -eq "" ) { $path = Read-Host "Enter the new filename" }
21+
22+
$pathToTemplate = Resolve-Path "$PSScriptRoot/../data/templates/Text.txt"
23+
Copy-Item $pathToTemplate "$path"
24+
if ($lastExitCode -ne 0) { throw "Can't copy template to: $path" }
25+
26+
"✅ New text file '$path' created from template 'Text.txt'."
27+
exit 0 # success
28+
} catch {
29+
"⚠️ Error: $($Error[0])"
30+
exit 1
31+
}

0 commit comments

Comments
 (0)