首页 > 代码库 > 为高效工作,运用powershell winrar 、unrar等 批量压缩、解压缩rar文件

为高效工作,运用powershell winrar 、unrar等 批量压缩、解压缩rar文件

为高效工作,运用powershell winrar 、unrar等 批量压缩、解压缩rar文件

首先在电脑上找到winrar,或者unrar所在地,我的win7 x64下 :

winrar 在 C:\Program Files (x86)\WinRAR\WinRAR.exeunrar 在 c:/Program Files (x86)/winrar/unrar.exe

zip.ps1

1 cls;2 $P = C:\Users\Patrick\Desktop\war\‘3 $winrar = C:\Program Files (x86)\WinRAR\WinRAR.exe4 Get-ChildItem -Path $p -Directory|%{5     &$winrar a "$($_).rar" $_ -y -ibck6     Start-Sleep -Milliseconds 2007 }
View Code

unzip.ps1

1 cls;2 $P = C:\Users\Patrick\Desktop\war\archive\‘3 $winrar = C:\Program Files (x86)\WinRAR\WinRAR.exe4 Get-ChildItem -Path "$($p)*.rar" -File|%{5     &$winrar x "$_" "$P" -y -ibck6     #Start-Sleep -Milliseconds 30007 }
View Code

unrar.ps1

1 cls;2 $P = C:\Users\Patrick\Desktop\war\‘3 $unrar = c:/Program Files (x86)/winrar/unrar.exe4 cd $p5 $rarfiles = @()6 ls "$P*.rar"|%{ 7     &$unrar x $_.FullName $_.name.Substring(0,$_.name.IndexOf(.)) –y 8 } 
View Code

例子:我的目录下有以下文件:

 1 PS E:\AddOn\005batch script\DB5\1010\TSQL> ls 2  3  4     目录: E:\AddOn\005batch script\DB5\1010\TSQL 5  6  7 Mode                LastWriteTime     Length Name 8 ----                -------------     ------ ---- 9 d----        2014/10/10     13:02            Archive10 -a---        2014/10/10     13:01        415 DUMMPREPVALIDATION.bat11 -a---        2014/10/10     13:02        524 DUMMPREPVALIDATION.ps112 -a---         2014/10/7     16:10       2180 DUMMPREPVALIDATION.SQL13 -a---        2014/10/10     13:01        375 DUMMYREP.bat14 -a---        2014/10/10     13:02        484 DUMMYREP.ps115 -a---         2014/10/7     16:09       1124 DUMMYREP.SQL16 17 18 PS E:\AddOn\005batch script\DB5\1010\TSQL>

运行,把6个文件,按文件名为包名,打包到Archive目录下,打包成DUMMYREP.rar和DUMMPREPVALIDATION.rar,每个包中分别包含xxx.bat,xxx.ps1,xxx.sql三个文件:

 1   2 cls 3 $pa = E:\AddOn\005batch script\DB5\1010\TSQL\‘ 4 $winrar = C:\Program Files (x86)\WinRAR\WinRAR.exe 5 cd $pa 6 ls "$($pa)*.sql"|%{ 7     $f = $_.name.Substring(0,$_.name.IndexOf(.)) 8     ls "$($f).*"|%{ 9         #&$winrar a "$($pa)$($f).rar" $_ -y -ibck10         &$winrar a "$($pa)Archive\$($f).rar" $_.Name -y -ibck11     }12 }

结果:

查看:

 

为高效工作,运用powershell winrar 、unrar等 批量压缩、解压缩rar文件