Powershell提取zip压缩包中的文件

下面是编程之家 jb51.cc 通过网络收集整理的代码片段。

编程之家小编现在分享给大家,也给大家做个参考。

###########################################################  
# AUTHOR  : Marius / Hican - http://www.hican.nl - @hicannl   
# DATE    : 26-06-2012   
# COMMENT : Search zip files for specific files and extract 
#           them to a (temp) directory. 
########################################################### 
 
#ERROR REPORTING ALL 
Set-StrictMode -Version latest 
 
#---------------------------------------------------------- 
#STATIC VARIABLES 
#---------------------------------------------------------- 
$search = "xml" 
$dest   = "D:\Hican\Temp" 
$zips   = "D:\Hican\Test" 
 
#---------------------------------------------------------- 
#FUNCTION GetZipFileItems 
#---------------------------------------------------------- 
Function GetZipFileItems 
{ 
  Param([string]$zip) 
   
  $split = $split.Split(".") 
  $dest = $dest + "\" + $split[0] 
  If (!(Test-Path $dest)) 
  { 
    Write-Host "Created folder : $dest" 
    $strDest = New-Item $dest -Type Directory 
  } 
 
  $shell   = New-Object -Com Shell.Application 
  $zipItem = $shell.NameSpace($zip) 
  $items   = $zipItem.Items() 
  GetZipFileItemsRecursive $items 
} 
 
#---------------------------------------------------------- 
#FUNCTION GetZipFileItemsRecursive 
#---------------------------------------------------------- 
Function GetZipFileItemsRecursive 
{ 
  Param([object]$items) 
 
  ForEach($item In $items) 
  { 
    If ($item.GetFolder -ne $Null) 
    { 
      GetZipFileItemsRecursive $item.GetFolder.items() 
    } 
    $strItem = [string]$item.Name 
    If ($strItem -Like "*$search*") 
    { 
      If ((Test-Path ($dest + "\" + $strItem)) -eq $False) 
      { 
        Write-Host "Copied file : $strItem from zip-file : $zipFile to destination folder" 
        $shell.NameSpace($dest).CopyHere($item) 
      } 
      Else 
      { 
        Write-Host "File : $strItem already exists in destination folder" 
      } 
    } 
  } 
} 
 
#---------------------------------------------------------- 
#FUNCTION GetZipFiles 
#---------------------------------------------------------- 
Function GetZipFiles 
{ 
  $zipFiles = Get-ChildItem -Path $zips -Recurse -Filter "*.zip" | % { $_.DirectoryName + "\$_" } 
   
  ForEach ($zipFile In $zipFiles) 
  { 
    $split = $zipFile.Split("\")[-1] 
    Write-Host "Found zip-file : $split" 
    GetZipFileItems $zipFile 
  } 
} 
#RUN SCRIPT  
GetZipFiles 
"SCRIPT FINISHED" 

以上是编程之家(jb51.cc)为你收集整理的全部代码内容,希望文章能够帮你解决所遇到的程序开发问题。

如果觉得编程之家网站内容还不错,欢迎将编程之家网站推荐给程序员好友。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


Centos系统之Shell编程基础知识
从Export理解Shell环境和变量生存期
linux shell数组变量、类型及规则
Centos编程Shell基本工作原理方案
Centos操作系统编程之Shell 问答录
rsync-linux备份脚本
Linux Shell编程入门 1-4
用shc加密shell脚本
centos每天自动备份mysql数据库
shell字符串处理
awk 用法:awk ' pattern {action} ' 变量名 含义 ARGC 命令行变元个数 ARGV 命令行变元数组 FI
sed之仅打印相邻重复的行 cat file aaa bbb bbb ccc ddd eee eee fff 只显示重复的行: bbb bbb eee eee sed -n ':a;N;/\(
压缩: tar -zcvf 压缩后文件名.tar.gz 被压缩文件 解压: tar -zxvf 被解压文件 注意:不要有多余的空格,一个空格即可。 具体的可以在linux环境下 用 tar --hel
sed命令行格式为: sed [-nefri] ‘command’ 输入文本/文件 常用选项: -n∶取消默认的输出,使用安静(silent)模式。在一般 sed 的用法中,所有来自 STDIN的资料
#假设文件名是:fortest.gtfdeclare -i fileLinesfileLines=`sed -n '$=' fortest.gtf`echo $fileLines#--
获得每行的最后一个逗号后边的内容.例如:KIAA1967 KIAA1967, xxxxSECIS biding proin 2-like, SECISBP2L, yyyy 1234ankyrin re
bash 正则表达式匹配,一行文本中 “包含 ABC” 并且 “不包含 XYZ”A文件: XXXX ABC XXX4444444444444444XXXX ABC XXX XYZ66666666666
shell/bash 让vi/vim显示空格,及tab字符Vim 可以用高亮显示空格和TAB。文件中有 TAB 键的时候,你是看不见的。要把它显示出来::set listTAB 键显示为 ^I, $显
输出到文件log中,并在屏幕上显示:#ls >&1 | tee log追加输出到文件log中,并在屏幕上显示:#ls >&1 | tee -a log
Suppose we have a file contains the following information, termed input_file:A 0B 1C 21.Read file on