执行这段代码时,我收到以下错误:
$filesExist = Test-Path($file)
if ($filesExist) {
$shell_app=new-object -com shell.application
$zip_file = Get-Item "$mindCrackFolder\files.zip"
$destination = Get-Item $mindCrackFolder
$destination.Copyhere($zip_file.items(), 0x14)
#Remove-Item "$zip_file"
#Remove-Item "install.ps1"
}
错误:
Method invocation failed because [System.IO.FileInfo] doesn't contain a method named 'items'.
At C:\Users\User1\Desktop\ps install\install.ps1:33 char:5
+ $destination.Copyhere($zip_file.items(), 0x14)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : MethodNotFound
但是我已经把$destination转换成了一个IO对象来操作了?我第一次尝试 PS,能得到任何帮助吗?
最佳答案
这与 $destination 无关。 $zip_file.items()
首先被评估,错误消息告诉您 Get-Item
返回的 .NET System.IO.FileInfo 对象没有 Items()
方法。 Get-Item
仅返回一个对象,该对象提供有关文件的信息 - 大小、上次写入时间、是否只读等。您不能使用 Get-Item 访问 ZIP 文件的内容。
如果您需要提取 ZIP 文件的内容,请考虑使用 PowerShell Community Exensions' 展开归档
cmdlet。
关于windows - PowerShell,不包含方法 'items',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14219783/