繁体   English   中英

读取zip文件中的文件名,而不在powershell中提取它

[英]Read a filename inside a zip file without extracting it in powershell

我有一个.zip文件file.zip 此zip文件中有很多文件,只有一个扩展名为.txt文本文件。 我想读一下这个文本文件的名称。 有没有办法在不在Powershell或C#中解压缩zip文件的情况下读取名称?

如果你有.Net 4.5,你可以运行这样的东西

[Reflection.Assembly]::LoadWithPartialName( "System.IO.Compression.FileSystem" );
$zipContens = [System.IO.Compression.ZipFile]::OpenRead("C:\path\file.zip");  
$zipContens.Entries | % {
   if ($_.Name -match "TheFileYouAreLookingFor.txt"){
       # found, your code block
   }
}

这个问题将有所帮助: Powershell基于单词/短语搜索文件,但也搜索Zip文件和zip文件

您可以使用Shell.Application对象枚举zip文件中的文件名:

$zip = 'C:\path\to\file.zip'

$app = New-Object -COM 'Shell.Application'
$app.NameSpace($zip).Items() | ? { $_.Name -like '*.txt' } | select -Expand Name

暂无
暂无

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

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