gpt4 book ai didi

Powershell解压错误

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

我从互联网上获得了以下脚本,当我尝试运行它时出现错误。

#script
#unzip folder

$shell_app = new-object -com shell.application
$filename = "test.zip"
$zip_file = $shell_app.namespace("C:\temp\$filename")

#set the destination directory for the extracts
$destination = $shell_app.namespace("C:\temp\zipfiles")

#unzip the file
$destination.Copyhere($zip_file.items())

- - 错误信息
    You cannot call a method on a null-valued expression.
At line:1 char:22
+ $destination.Copyhere <<<< ($zip_file.items())
+ CategoryInfo : InvalidOperation: (Copyhere:String) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull

最佳答案

在设置 $destination 变量之前,您需要创建“c:\temp\zipfiles”文件夹,
这种草率的方式,但它会做的工作:)

#script
#unzip folder

$shell_app = new-object -com shell.application
$filename = "test.zip"
$zip_file = $shell_app.namespace("C:\temp\$filename")

#set the destination directory for the extracts
if (!(Test-Path "C:\temp\zipfiles\")) {
mkdir C:\temp\zipfiles
}
$destination = $shell_app.namespace("C:\temp\zipfiles")

#unzip the file
$destination.Copyhere($zip_file.items())

关于Powershell解压错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14490304/

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