标题: [转载代码] PowerShell提取zip压缩包中的文件名包含指定字符串的文件 [打印本页]
作者: DAIC 时间: 2013-10-28 17:29 标题: PowerShell提取zip压缩包中的文件名包含指定字符串的文件
- ###########################################################
- # 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"
复制代码
http://www.oschina.net/code/snippet_222150_18228
作者: hzcxdgioa 时间: 2013-11-28 22:08
谢谢lz分享。。。。。。。。。▓
欢迎光临 批处理之家 (http://bbs.bathome.net/) |
Powered by Discuz! 7.2 |