gpt4 book ai didi

powershell - 我想使用 powershell 在 temp 中的给定目录中提取所有 .zip 文件

转载 作者:行者123 更新时间:2023-12-03 16:28:52 26 4
gpt4 key购买 nike

我编写了以下代码来将 .zip 文件解压缩到 temp:

function Expand-ZIPFile($file, $destination)
{
$shell = new-object -com shell.application
$zip = $shell.NameSpace($file)
foreach ($item in $zip.items()) {
$shell.Namespace($destination).copyhere($item)
}
}

Expand-ZIPFile -file "*.zip" -destination "C:\temp\CAP"

但我收到以下错误:
PS C:\Users\v-kamoti\Desktop\CAP> function Expand-ZIPFile($file, $destination)
{
$shell = new-object -com shell.application
$zip = $shell.NameSpace($file)
foreach ($item in $zip.items()) {
$shell.Namespace($destination).copyhere($item)
}
}

Expand-ZIPFile -file "*.zip" -destination "C:\temp\CAP"
You cannot call a method on a null-valued expression.
At line:5 char:19
+ foreach($item in $zip.items())
+ ~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException

最佳答案

Get-ChildItem 'path to folder' -Filter *.zip | Expand-Archive -DestinationPath 'path to extract' -Force

需要 ps v5

关于powershell - 我想使用 powershell 在 temp 中的给定目录中提取所有 .zip 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28448202/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com