如果你安裝了winrar且安裝在對應下面的路徑,可以嘗試一下下面的代碼(事實上我也是copy並修改自網上的代碼)<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />
- $unrar = “c:/Program files/winrar/unrar.exe”
- &$unrar
呵呵據我所知 rar.exe / unrar.exe是winrar 的核心,winrar就是調用它們來壓縮和解壓的。如前所述,我想讓winrar替我解壓東西,我就必須瞭解 unrar.exe 的參數。
<?xml:namespace prefix = v ns = "urn:schemas-microsoft-com:vml" />
看到了上面代碼的輸出結果沒,其中解釋了unrar的調用方式?目前我要解壓到以當前日期爲名字的文件夾,所以我用
- Unrar x xxx.rar destinationFolder –y
來解壓,它將xxx.rar 解壓到文件夾 destinationFolder 並對所有問題(比如是否覆蓋已有同名文件)回答yes。
嗯就剩一個問題了,怎麼得到winrar的路徑呢,它不一定總在c:/Program files下。可以用下面的代碼,明天繼續分析嘿嘿~~~
- $s = gp hklm:/Software/Classes/WinRAR/shell/open/command | findstr "(default)"
- if ($s -eq $null)
- {
- Write-host "請先安裝WinRAR"
- }
- Else
- {
- Write-host "WinRAR已經安裝好了"
- }