mirror of
https://github.com/fleschutz/PowerShell.git
synced 2025-07-14 19:35:03 +02:00
Added a check if file is already existing
This commit is contained in:
@ -1,13 +1,13 @@
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Creates a new Markdown file
|
||||
Creates a Markdown file
|
||||
.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: ../data/templates/New.md.
|
||||
.PARAMETER path
|
||||
Specifies the path and new filename (README.md by default)
|
||||
.EXAMPLE
|
||||
PS> ./new-markdown-file.ps1
|
||||
✅ New file 'README.md' created from template 'Markdown.md'.
|
||||
✅ New 'README.md' created (from data/templates/New.md).
|
||||
.LINK
|
||||
https://github.com/fleschutz/PowerShell
|
||||
.NOTES
|
||||
@ -17,11 +17,13 @@
|
||||
param([string]$path = "README.md")
|
||||
|
||||
try {
|
||||
$pathToTemplate = Resolve-Path "$PSScriptRoot/../data/templates/Markdown.md"
|
||||
if (Test-Path "$path" -pathType leaf)) { throw "File '$path' is already existing" }
|
||||
|
||||
$pathToTemplate = Resolve-Path "$PSScriptRoot/../data/templates/New.md"
|
||||
Copy-Item $pathToTemplate "$path"
|
||||
if ($lastExitCode -ne 0) { throw "Can't copy template to: $path" }
|
||||
|
||||
"✅ New file '$path' created from template 'Markdown.md'."
|
||||
"✅ New '$path' created (from data/templates/New.md)."
|
||||
exit 0 # success
|
||||
} catch {
|
||||
"⚠️ Error: $($Error[0])"
|
||||
|
@ -17,6 +17,8 @@
|
||||
param([string]$path = "bot.ps1")
|
||||
|
||||
try {
|
||||
if (Test-Path "$path" -pathType leaf)) { throw "File '$path' is already existing" }
|
||||
|
||||
$pathToTemplate = Resolve-Path "$PSScriptRoot/../data/templates/New.ps1"
|
||||
Copy-Item $pathToTemplate "$path"
|
||||
if ($lastExitCode -ne 0) { throw "Can't copy to: $path" }
|
||||
|
@ -17,6 +17,8 @@
|
||||
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" }
|
||||
|
Reference in New Issue
Block a user