# Author: Icebird@cnblogs# Purpose: RAR2ZIPfunction Global:rar2zip($rarfile = $(throw "缺少参数"), $zipfile = ""){trap{ $_.InvocationInfo write-host ("{0,-17:S}{1} {2}" -f "Exception", ":", $_.Exception.Message) break}function exist($path, $name){ return (dir $path | ? { $_.Name -eq $name } | measure-object).Count -gt 0}function deltree($path, $name){ if (exist "$path" "$name") { del "$path\$name" -recurse }}$s = gp hklm:\Software\Classes\WinRAR\shell\open\command | findstr "(default)"if ($s -eq $null){ return "请先安装WinRAR"}[regex] $regex = "`"(.+?)`""$rar = ($regex.matches($s))[0].Groups[1].Value -replace "WinRAR.exe","RAR.exe"$s = dir "$rarfile"if ($s -eq $null){ return "$rarfile 不存在"}$tempdir = ${env:Temp} + "\rar2zip"deltree ${env:Temp} "rar2zip"md $tempdir > $null&$rar x "$rarfile" "$tempdir"if ($zipfile -eq ""){ if ($rarfile -match ".rar$") { $zipfile = $rarfile -replace ".rar$",".zip" } else { $zipfile = $rarfile + ".zip" }}pkzip25 -add -max -rec -path=relative "$zipfile" "$tempdir\*.*"deltree ${env:Temp} "rar2zip"} 这段脚本将增加一个全局函数rar2zip,用途是将rar文件转换成zip文件注意:1. 需要安装WinRAR2. PKZIP25.EXE在搜索路径里的任意目录内Usage:rar2zip mydoc.rarrar2zip mydoc.rar doc.zippkzip25.exe下载:https://files.cnblogs.com/Icebird/PKZIP25.rar 相关文章: 2021-06-05 2021-05-20 2022-02-15 2021-08-27 2021-11-23 2022-02-08 2022-12-23 2021-10-03