繁体   English   中英

powershell - 从zip中提取文件类型

[英]powershell - extract file type from zip

我有一个随机文件名的zip文件,它包含在一个随机命名的zip文件中。 我正在改进以下示例代码:

$shell = new-object -com shell.application
 $zip = $shell.NameSpace(“C:\howtogeeksite.zip”)
foreach($item in $zip.items())
 {
 $shell.Namespace(“C:\temp\howtogeek”).copyhere($item)
 }

外部zipfile包含我不需要的几百个文件以及其中的一个zip文件 - 如何优化上述源代码以仅获取内部zip文件(它可以从外部zip文件中提取所有文件,其扩展名为。 zip)...请告知最简单的方法。 谢谢!

在提取之前,您需要迭代内容检查每个项目的文件扩展名是否为“.zip”。 这样的事情应该有效:

$shell = new-object -com shell.application
$zip = $shell.NameSpace(“C:\howtogeeksite.zip”)

foreach($item in $zip.items()){

    if([System.IO.Path]::GetExtension($item.Path) -eq ".zip"){

        $shell.Namespace(“C:\temp\howtogeek”).copyhere($item)

    }

}

暂无
暂无

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

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