Skip to content

Instantly share code, notes, and snippets.

@milnak
Last active February 26, 2025 20:06
Show Gist options
  • Save milnak/11bd7624ff149e78908e81787358dd53 to your computer and use it in GitHub Desktop.
Save milnak/11bd7624ff149e78908e81787358dd53 to your computer and use it in GitHub Desktop.
Backup Double Commander settings folder using 7z
Param(
[string]$SourcePath = '~\scoop\persist\doublecmd',
[string]$DestinationPath = (Resolve-Path '~').Path,
[string]$Filename = 'DoubleCmd Backup {0}' -f (Get-Date -Format '(yyyy-MM-dd)')
)
# Ensure 7z.exe exists
Get-Command '7z.exe' -CommandType Application -ErrorAction Stop | Out-Null
$archiveName = '{0}.7z' -f (Join-Path -Path $DestinationPath -ChildPath $Filename)
if (Test-Path -LiteralPath $archiveName -PathType Leaf -ErrorAction SilentlyContinue) {
Write-Warning 'Archive already exists.'
return
}
$arguments = `
# a : Add files to archive
'a', `
# -bb[0-3] : set output log level
'-bb3', `
# -r[-|0] : Recurse subdirectories for name search
'-r', `
# -mx[N] : set compression level: -mx1 (fastest) ... -mx9 (ultra)
'-mx9', `
# -x[r[-|0]][m[-|2]][w[-]]{@listfile|!wildcard} : eXclude filenames
'-x!*.exe', `
# <archive_name>
('"{0}"' -f $archiveName), `
# [<file_names>...]
'"*"'
Push-Location $SourcePath
Start-Process -FilePath '7z.exe' -ArgumentList $arguments -NoNewWindow -Wait
Pop-Location
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment