700字范文,内容丰富有趣,生活中的好帮手!
700字范文 > PowerShell 学习笔记:压缩 解压缩文件

PowerShell 学习笔记:压缩 解压缩文件

时间:2024-04-13 13:36:28

相关推荐

PowerShell 学习笔记:压缩 解压缩文件

在自动构建的时候,最常用的就是压缩备份项目的源文件,PowerShell提供了相关命令。

Compress-Archive(压缩文件)

Compress-Archive[-Path] <String[]>[-DestinationPath] <String>[-CompressionLevel <String>][-PassThru][-WhatIf][-Confirm][<CommonParameters>]

参数说明:

举例:备份如下目录中的文件,但是不包含:node_modules 子目录

备份的zip文件位于: Z:\Documents\sensorwu\VUE\VUE3\Backup.zip

$compress = @{Path = "Z:\Documents\sensorwu\VUE\VUE3\szhn_app_vue3\dist", "Z:\Documents\sensorwu\VUE\VUE3\szhn_app_vue3\public","Z:\Documents\sensorwu\VUE\VUE3\szhn_app_vue3\src","Z:\Documents\sensorwu\VUE\VUE3\szhn_app_vue3\*.*"CompressionLevel = "Fastest"DestinationPath = "Z:\Documents\sensorwu\VUE\VUE3\Backup.zip"}Compress-Archive @compress

压缩后文件用winrar打开:

$compress = @{Path = "Z:\Documents\sensorwu\VUE\VUE3\szhn_app_vue3\*"CompressionLevel = "Fastest"DestinationPath = "Z:\Documents\sensorwu\VUE\VUE3\Backup.zip"}Compress-Archive @compress

Expand-Archive(解压缩文件)

Expand-Archive[-Path] <String>[[-DestinationPath] <String>][-Force][-PassThru][-WhatIf][-Confirm][<CommonParameters>]

举例:将上面备份的文件解压缩到:Z:\Documents\sensorwu\VUE\VUE3\szhn_Demo 目录中。

Expand-Archive -Path "Z:\Documents\sensorwu\VUE\VUE3\Backup.zip" -DestinationPath "Z:\Documents\sensorwu\VUE\VUE3\szhn_Demo"

解压后的效果:

在学习PowerShell之前,我使用的是WinRar的命令行模式,也可以实现压缩和解压缩功能,但是有个问题就是必须安装WinRar,使用PowerShell就无需安装WinRar程序了。

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。