# 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 相关文章: 下载zip格式文件(压缩Excel文件为zip格式) 2021-09-20 将windows文本格式转换为UNIX格式 2021-11-14 Linux将文件强制转换为dos格式、unix格式 2021-06-09 如何将excel文件转换为csv格式 2021-10-22 如何将.crt文件转换为.cer格式 2021-12-06 将文件打包为zip(转) 2021-11-13 PDF可以转换为CAD格式吗?怎么将PDF文件转换为CAD格式? 2021-10-19