标题: [原创代码] PowerShell提取zip压缩包指定扩展名的文件 [打印本页]
作者: DAIC 时间: 2013-10-29 15:38 标题: PowerShell提取zip压缩包指定扩展名的文件
- #ERROR REPORTING ALL
- Set-StrictMode -Version latest
-
- #----------------------------------------------------------
- #STATIC VARIABLES
- #----------------------------------------------------------
- $ext = "xml"
- $dest = "D:\Test\bbb"
- $zips = "D:\Test\aaa"
-
- #----------------------------------------------------------
- #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 -Match "\.$ext$")
- {
- 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://bbs.bathome.net/thread-26996-1-1.html
欢迎光临 批处理之家 (http://bbs.bathome.net/) |
Powered by Discuz! 7.2 |