我有以下 .ps1 用于解压缩 zip 文件...
param([string]$path)
$shell=new-object -com shell.application
$Location=$shell.namespace($path)
$ZipFiles = get-childitem *.zip
get-childitem $path -include *.xml -recurse | foreach ($_) {remove-item $_.fullname}
foreach ($ZipFile in $ZipFiles)
{
$ZipFile.fullname | out-default
$ZipFolder = $shell.namespace($ZipFile.fullname)
$Location.Copyhere($ZipFolder.items())
}
以及以下用于设置参数和调用 .ps1 的 run.bat 文件
powershell -command "C:\Users\eric\unzipFile\unzip3.ps1 -path \"C:\Users\eric\unzipFile\""
如果两者都在同一个目录中,则没有错误,但是如果我将 run.bat 移动到另一个目录,我会得到以下...
You cannot call a method on a null-valued expression.
At C:\Users\eric\unzipFile\unzip3.ps1:12 char:38
+ $Location.Copyhere($ZipFolder.items <<<< ())
+ CategoryInfo: InvalidOperation: (items:String) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull