Skip to content

Instantly share code, notes, and snippets.

@Cologler
Last active February 21, 2020 15:13
Show Gist options
  • Save Cologler/835e2f385d62d367e8732cced06d76fa to your computer and use it in GitHub Desktop.
Save Cologler/835e2f385d62d367e8732cced06d76fa to your computer and use it in GitHub Desktop.
a script that create a *.bak file for target file
param(
[Parameter(Position=0, mandatory=$true)]
[string] $Path
)
function RenameBak {
param (
[string] $Path
)
if (Test-Path $Path) {
$BakPath = "$Path.bak"
RenameBak $BakPath
Rename-Item -NewName $BakPath $Path
}
}
function MakeBak {
param (
[string] $Path
)
$BakPath = "$Path.bak"
RenameBak $BakPath
Copy-Item -Path $Path -Destination $BakPath -Recurse
}
MakeBak $Path
param(
[Parameter(Position=0, mandatory=$true)]
[string] $Path
)
$BakPath = "$Path.bak"
if (Test-Path $BakPath) {
Remove-Item $Path -Recurse
Rename-Item -NewName $Path $BakPath
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment