简体   繁体   English

读取 Powershell 中的 zip 文件(openread)

[英]Reading zip file in Powershell (openread)

I am trying to read zip file by openread method, but it gives error that could not find zip file.我正在尝试通过 openread 方法读取 zip 文件,但它给出了找不到 zip 文件的错误。 Below is the code that I am using:下面是我正在使用的代码:

Code:代码:

$Sourcefolder= "C:\Users\My.pc\Downloads"

$Myzipfile= gci $Sourcefolder -Filter *.zip | sort LastWriteTime | select -last 1

Add-Type -AssemblyName System.IO.Compression.FileSystem

$zip = [System.IO.Compression.ZipFile]::OpenRead($Myzipfile)

Error:错误:

Exception calling "OpenRead" with "1" argument(s): "Could not find file 'C:\Users\My.pc\15367448612289827.zip'."
At line:4 char:1
+ $zip = [System.IO.Compression.ZipFile]::OpenRead($Myzipfile)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : FileNotFoundException

What should I do?我应该怎么办? any help please.请提供任何帮助。

Change $Myzipfile to $Myzipfile.FullName :将 $ $Myzipfile更改为$Myzipfile.FullName

$zip = [System.IO.Compression.ZipFile]::OpenRead($Myzipfile.FullName)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM