|
本帖最后由 kingshui 于 2021-12-31 11:36 编辑
如标题,就是一个使用windows自带工具(内外置命令)写的一个方便打包文件的小工具
将文件或者文件夹拖放到批处理上会自动生成另一个自解压的批处理,生成的批处理自带父文件的打包功能,可重复利用。
- @echo off
- set "_n=%~0"
- if "%~1" NEQ "" goto packagemod
- for /f "usebackq delims==" %%a in ("%_n%") do set "name=%%a"
- certutil -decode "%_n%" "%~n0.cab"
- md "%~n0"
- expand -r "%~n0.cab" ".\%~n0" |find "-F" && expand "%~n0.cab" -F:* ".\%~n0" >nul
- del "%~n0.cab" & explorer "%~n0"
- exit
- :packagemod
- set cmdstr=MAKECAB /v3 /D CompressionType=LZX /D CompressionMemory=21 /D MaxDiskSize=CDROM /D Cabinet=On /D Compress=On /D FolderSizeThreshold=5000000 /D DiskDirectoryTemplate="%~dp1." /D CabinetNameTemplate="tmp.cab"
- if exist "%~1" (
- for /f "delims=" %%a in ('dir "%~1" /a-d /s /b') do (
- setlocal enabledelayedexpansion
- set x=%%a
- set x=!x:%~dp1=!
- echo "%%a" "!x!">>cabstr
- endlocal
- )) else (
- echo "%~1" "%~nx1" >>cabstr
- )
- if "%~2" neq "" shift&goto packagemod
- %cmdstr% /F cabstr >nul
- del /f/q patch cab cabstr SETUP.INF SETUP.RPT >nul
- powershell -C "& {$outpath = (Join-Path (pwd) '%~n1.base64'); $inpath = (Join-Path (pwd) 'tmp.cab'); [IO.File]::WriteAllText($outpath, ([convert]::ToBase64String(([IO.File]::ReadAllBytes($inpath)))))}"
- for /f "delims=" %%i in (%_n%) do (
- if "%%i" EQU ":encoding" goto :next
- echo,%%i>>"%~n1.cmd"
- )
- :next
- set "certb=BEGIN CERTIFICATE"
- set "certe=END CERTIFICATE"
- set "dash=-----"
- echo :encoding>>"%~n1.cmd"
- echo,%dash%%certb%%dash%>>"%~n1.cmd"
- type "%~n1.base64" >>"%~n1.cmd"
- echo,>>"%~n1.cmd"
- echo,%dash%%certe%%dash%>>"%~n1.cmd"
- echo %~nx1>>"%~n1.cmd"
- del tmp.cab "%~n1.base64"
- exit
复制代码
|
|