PowerShell如何将每个zip文件解压到与压缩包同名的无后缀子文件夹
批量解压zip到同名无后缀文件夹的PowerShell简洁写法
1行实现(默认覆盖已有目标文件)
Get-ChildItem *.zip | ForEach-Object { Expand-Archive $_.FullName -DestinationPath ($_.FullName -replace '\.zip$', '') -Force }
带目标文件夹存在判断的2行写法(仅文件夹不存在时解压)
Get-ChildItem *.zip | ForEach-Object { $dst = $_.FullName -replace '\.zip$', '' if (!(Test-Path $dst)) { Expand-Archive $_.FullName -DestinationPath $dst } }
说明
- 要遍历当前目录及所有子目录的zip文件,在
Get-ChildItem后添加-Recurse参数即可 - 要指定扫描的根目录,将
Get-ChildItem *.zip修改为Get-ChildItem 你的目标路径\*.zip - 写法依赖PowerShell 5.1及以上版本内置的
Expand-Archive命令,Windows 10/11及Server 2016以上系统默认自带无需额外安装
内容的提问来源于stack exchange,提问作者YorSubs
相关产品推荐
相关产品推荐

