windows - PowerShell,不包含方法 'items'

标签 windows string file powershell io

执行这段代码时,我收到以下错误:

$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/

相关文章:

c++ - 将 char * 转换为 LPWSTR

c++ - 如何在运行时将字符串转换为代码

c# - 组合 C# String.Format 格式选项

c# - 有没有一种简单的方法来解析 C# 中的结构化文本文件?

windows - 用 Go 编写的目录 walker 因文件正在使用(锁定)错误而停止

linux - 在 git bash 中设置斜杠目录

windows - 用于保留缓冲区的 Powershell Clear-Host 替代方案

windows - 用于调试异常内存泄漏的调试技术

java - 读取序列化文件 - java

c - 使用 fseek() 读取文件的最后 50 个字符