Powershell呼叫7zip

如果在powershell 發現找不到7z 指令,可以用下面的script替代

1
2
3
4
5
6
7
8
9
10
11
12
$7zipPath = "$env:ProgramFiles\7-Zip\7z.exe"

if (-not (Test-Path -Path $7zipPath -PathType Leaf)) {
throw "7 zip file '$7zipPath' not found"
}

Set-Alias 7zip $7zipPath

$Source = "c:\BackupFrom\backMeUp.txt"
$Target = "c:\BackupFolder\backup.zip"

7zip a -v50m -mx=9 $Target $Source #-v50m 代表將檔案分割成每50MB一包

7-zip 指令參考


參考:
https://stackoverflow.com/a/25288780

Author

Steven

Posted on

2022-06-24

Updated on

2025-01-14

Licensed under

Comments