用 Compress-Archive 打包 zip 文件
直接在 PowerShell 中把任意文件或文件夹内容创建为 zip 压缩包。
运行 `Compress-Archive -Path .\project\* -DestinationPath .\project-backup.zip` 压缩文件夹内容。
01命令
命令
$ Compress-Archive -Path .\project\* -DestinationPath .\project-backup.zip -Force02作用说明
Compress-Archive 生成的是标准 ZIP 文件,资源管理器可以直接打开。`Path 文件夹\*` 压缩文件夹内的内容,`Path 文件夹` 则把文件夹本身作为子目录打包。如果目标文件已存在,可用 -Update 只更新有变化的文件,或用 -Force 整体覆盖。对应的 Expand-Archive 负责解压。
03风险
04撤销
✓无需撤销——该命令不会改变持久状态。
05来源
- Compress-Archive (Microsoft.PowerShell.Archive)依据: Documents Compress-Archive with -Path, -DestinationPath, -Force and the update behavior when the destination zip exists.
最后验证: 2026-09-17 · 分类: 文件与文件夹