主要是为了方便发布制作中的小游戏,但是作为日常使用也算是够用了.
下面还个保留空目录的,不过会在压缩包里有0字节的San.Dir临时文件
不保留空目录,不产生临时文件
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 |
@echo off title 任务执行中... mode con:cols=30 lines=1 setlocal enableextensions setlocal enabledelayedexpansion rem 修改自 "NCAB" V1.12 原作者:NicTense rem 以下是大致的功能和修改内容: rem 压缩文件/文件夹,为微软 .CAB格式文件 rem 压缩比率为最大,保留优先处理.inf文件 rem 修改了右键菜单,区分文件和文件夹选项 rem 添加右键子菜单及图标,不保留空的目录 rem 增加几处判断,避免重复操作导致的问题 rem 代码排版按个人喜好重新排,并添加注释 rem 更名为 SanCAB by ZhangZsky 18/04/29 rem 后续更新:http://blog.snote.cn/sancab-bat if "%1"=="" goto Page if /i "%~1"=="/reg" goto Install if not "%2"=="" goto %2 :SanCAB rem 文件夹压缩 if not exist "%~1" exit dir "%~1" /ad>nul 2>nul||exit pushd "%~f1\" rem 预处理 for /f "tokens=*" %%b in ( 'dir *.inf /a-d /on /b 2^>nul' ) do ( echo "%~f1\%%~b">>"%temp%\%~n1.tmp" ) rem 先列出.inf文件 for /f "tokens=*" %%b in ( 'dir * /a-d /on /b 2^>nul' ) do ( if /i "%%~xb" neq ".inf" echo "%~f1\%%~b">>"%temp%\%~n1.tmp" ) rem 再列出非.inf的文件 for /f "tokens=*" %%a in ( 'dir * /s /ad /on /b 2^>nul' ) do ( set d=%%~a set d=!d:%~f1\=! rem 获取子文件夹名称 for /f "usebackq tokens=*" %%b in ( `dir "%%~a\*.inf" /a-d /on /b 2^>nul` ) do ( echo "%%~a\%%~b" "!d!\%%~b">>"%temp%\%~n1.tmp" ) rem 列出子文件夹的.inf文件 for /f "usebackq tokens=*" %%b in ( `dir "%%~a\*" /a-d /on /b 2^>nul` ) do ( if /i "%%~xb" neq ".inf" echo "%%~a\%%~b" "!d!\%%~b">>"%temp%\%~n1.tmp" ) rem 再列出子文件夹非.inf的文件 ) makecab.exe /V3 /D CompressionType=LZX /D CompressionMemory=21 /D MaxDiskSize=0 /D FolderSizeThreshold=2147483648 /D DiskDirectoryTemplate="%~dp1." /D CabinetNameTemplate="%~n1.cab" /D InfFileName="%temp%\%~n1.inf" /D RptFileName="%temp%\%~n1.rpt" /F "%temp%\%~n1.tmp" for %%a in ( inf rpt tmp ) do ( del /s /q "%temp%\%~n1.%%a">nul 2>nul ) rem 删除临时文件及列表 goto :eof :FileSanCAB rem 文件压缩 if not exist "%~1" exit dir "%~1" /ad>nul 2>nul&&exit rem 预处理 set /p=<nul>"%temp%\SNote.CN" echo "%~1">"%temp%\%~n1.tmp" echo "%temp%\SNote.CN">>"%temp%\%~n1.tmp" makecab.exe /V3 /D CompressionType=LZX /D CompressionMemory=21 /D MaxDiskSize=0 /D FolderSizeThreshold=2147483648 /D DiskDirectoryTemplate="%~dp1." /D CabinetNameTemplate="%~n1.cab" /D InfFileName="%temp%\%~n1.inf" /D RptFileName="%temp%\%~n1.rpt" /F "%temp%\%~n1.tmp" for %%a in ( inf rpt tmp ) do ( rem del /s /q "%temp%\%~n1.%%a">nul 2>nul ) rem 删除临时文件及列表 goto :eof :UnSanCAB rem 解压缩 if not exist "%~1" exit if /i not "%~x1"==".cab" exit rem 预处理 md "%~n1" expand "%1" /f:*.* "%~dp1\%~n1" cd "%~n1" del /s /q SNote.CN>nul 2>nul exit :Page mode con:cols=45 lines=15 fltmc>nul&&(title 已获得管理员权限)||(title 未获得管理员权限) cls echo. echo SanCAB压缩 文件/文件夹 右键菜单 echo. echo 提示:避免多文件/文件夹同时压缩^^! echo. echo ( I 安装 / U 卸载 / Q 退出 ) echo. echo. set /p o=请输入: if /i "%o%"=="I" goto Install if /i "%o%"=="U" goto UnInstall if /i "%o%"=="Q" exit goto Page :Install reg add HKCR\*\shell\SanCAB菜单项 /v icon /t REG_SZ /d "iexpress.exe" /f>nul 2>nul reg add HKCR\*\shell\SanCAB菜单项 /v MUIVerb /t REG_SZ /d "SanCAB菜单" /f>nul 2>nul reg add HKCR\*\shell\SanCAB菜单项 /v SubCommands /t REG_SZ /d "SanCAB菜单压缩项;SanCAB菜单解压项" /f>nul 2>nul reg add HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\CommandStore\shell\SanCAB菜单压缩项 /ve /t REG_SZ /d "SanCAB压缩此文件" /f>nul 2>nul reg add HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\CommandStore\shell\SanCAB菜单压缩项 /v icon /t REG_SZ /d "iexpress.exe" /f>nul 2>nul reg add HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\CommandStore\shell\SanCAB菜单压缩项\command /ve /t REG_SZ /d "%SystemRoot%\system32\SanCAB.Bat %%1 FileSanCAB" /f>nul 2>nul reg add HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\CommandStore\shell\SanCAB菜单解压项 /ve /t REG_SZ /d "SanCAB解压此文件" /f>nul 2>nul reg add HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\CommandStore\shell\SanCAB菜单解压项 /v icon /t REG_SZ /d "iexpress.exe" /f>nul 2>nul reg add HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\CommandStore\shell\SanCAB菜单解压项\command /ve /t REG_SZ /d "%SystemRoot%\system32\SanCAB.Bat %%1 UnSanCAB" /f>nul 2>nul reg add HKCR\Directory\shell\SanCAB压缩文件夹 /v icon /t REG_SZ /d "iexpress.exe" /f>nul 2>nul reg add HKCR\Directory\shell\SanCAB压缩文件夹\command /ve /t REG_SZ /d "%SystemRoot%\system32\SanCAB.Bat %%1 SanCAB" /f>nul 2>nul reg query HKCR\Directory\shell\SanCAB压缩文件夹\command|FIND /i "SanCAB.Bat">nul||goto Admin copy /y "%~0" "%SystemRoot%\system32\SanCAB.Bat">nul 2>nul if not exist "%SystemRoot%\system32\SanCAB.Bat" goto Admin if /i "%~1"=="/reg" exit echo. echo. echo 安装成功,可在任意文件或目录上使用. echo. echo 按任意键退出... pause>nul exit :UnInstall reg delete HKCR\*\shell\SanCAB菜单项 /f>nul 2>nul reg delete HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\CommandStore\shell\SanCAB菜单压缩项 /f>nul 2>nul reg delete HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\CommandStore\shell\SanCAB菜单解压项 /f>nul 2>nul reg delete HKCR\Directory\shell\SanCAB压缩文件夹 /f>nul 2>nul reg query HKCR\Directory\shell\SanCAB压缩文件夹>nul 2>nul&&goto Admin del /s /q "%SystemRoot%\system32\SanCAB.Bat">nul 2>nul if exist "%SystemRoot%\system32\SanCAB.Bat" goto Admin echo. echo. echo 卸载成功,相关文件和右键菜单已删除. echo. echo 按任意键退出... pause>nul exit :Admin echo. echo. echo 操作失败,必须以右键管理员权限运行. echo. echo 按任意键退出... pause>nul exit |
保留空目录,产生临时文件
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 |
@echo off title 任务执行中... mode con:cols=30 lines=1 setlocal enableextensions setlocal enabledelayedexpansion rem 修改自 "NCAB" V1.12 原作者:NicTense rem 以下是大致的功能和修改内容: rem 压缩文件/文件夹,为微软 .CAB格式文件 rem 压缩比率为最大,保留优先处理.inf文件 rem 修改了右键菜单,区分文件和文件夹选项 rem 添加右键子菜单及图标,保留空压缩目录 rem 增加几处判断,避免重复操作导致的问题 rem 代码排版按个人喜好重新排,并添加注释 rem 更名为 SanCAB by ZhangZsky 18/04/27 rem 后续更新:http://blog.snote.cn/sancab-bat if "%1"=="" goto Page if /i "%~1"=="/reg" goto Install if not "%2"=="" goto %2 :SanCAB rem 文件夹压缩 if not exist "%~1" exit dir "%~1" /ad>nul 2>nul||exit pushd "%~f1\" rem 预处理 set /p=<nul>"%~f1\San.dir" for /f "tokens=*" %%b in ( 'dir *.inf /a-d /on /b 2^>nul' ) do ( echo "%~f1\%%~b">>"%temp%\%~n1.tmp" ) rem 先列出.inf文件 for /f "tokens=*" %%b in ( 'dir * /a-d /on /b 2^>nul' ) do ( if /i "%%~xb" neq ".inf" echo "%~f1\%%~b">>"%temp%\%~n1.tmp" ) rem 再列出非.inf的文件 for /f "tokens=*" %%a in ( 'dir * /s /ad /on /b 2^>nul' ) do ( set d=%%~a set d=!d:%~f1\=! rem 获取子文件夹名称 set /p=<nul>"!d!\San.dir" rem 避免空目录,全部建立临时文件 for /f "usebackq tokens=*" %%b in ( `dir "%%~a\*.inf" /a-d /on /b 2^>nul` ) do ( echo "%%~a\%%~b" "!d!\%%~b">>"%temp%\%~n1.tmp" ) rem 列出子文件夹的.inf文件 for /f "usebackq tokens=*" %%b in ( `dir "%%~a\*" /a-d /on /b 2^>nul` ) do ( if /i "%%~xb" neq ".inf" echo "%%~a\%%~b" "!d!\%%~b">>"%temp%\%~n1.tmp" ) rem 再列出子文件夹非.inf的文件 ) makecab.exe /V3 /D CompressionType=LZX /D CompressionMemory=21 /D MaxDiskSize=0 /D FolderSizeThreshold=2147483648 /D DiskDirectoryTemplate="%~dp1." /D CabinetNameTemplate="%~n1.cab" /D InfFileName="%temp%\%~n1.inf" /D RptFileName="%temp%\%~n1.rpt" /F "%temp%\%~n1.tmp" for %%a in ( inf rpt tmp ) do ( del /s /q "%temp%\%~n1.%%a">nul 2>nul ) rem 删除临时文件及列表 del /s /q "%~f1\San.dir" >nul 2>nul for /f "tokens=*" %%a in ( 'dir * /s /ad /on /b 2^>nul' ) do ( set d=%%~a set d=!d:%~f1\=! rem 获取子文件夹名称 del /s /q "!d!\San.dir" >nul 2>nul ) goto :eof :FileSanCAB rem 文件压缩 if not exist "%~1" exit dir "%~1" /ad>nul 2>nul&&exit rem 预处理 set /p=<nul>"%temp%\San.dir" echo "%temp%\San.dir">"%temp%\%~n1.tmp" echo "%~1">>"%temp%\%~n1.tmp" makecab.exe /V3 /D CompressionType=LZX /D CompressionMemory=21 /D MaxDiskSize=0 /D FolderSizeThreshold=2147483648 /D DiskDirectoryTemplate="%~dp1." /D CabinetNameTemplate="%~n1.cab" /D InfFileName="%temp%\%~n1.inf" /D RptFileName="%temp%\%~n1.rpt" /F "%temp%\%~n1.tmp" for %%a in ( inf rpt tmp ) do ( del /s /q "%temp%\%~n1.%%a">nul 2>nul ) rem 删除临时文件及列表 goto :eof :UnSanCAB rem 解压缩 if not exist "%~1" exit if /i not "%~x1"==".cab" exit rem 预处理 md "%~n1" expand "%1" /f:*.* "%~dp1\%~n1" cd "%~n1" del /s /q San.dir>nul 2>nul for /f "tokens=*" %%a in ( 'dir * /s /ad /on /b 2^>nul' ) do ( set d=%%~a set d=!d:%~f1\=! rem 获取子文件夹名称 del /s /q "!d!\San.dir" >nul 2>nul ) exit :Page mode con:cols=45 lines=15 fltmc>nul&&(title 已获得管理员权限)||(title 未获得管理员权限) cls echo. echo SanCAB压缩 文件/文件夹 右键菜单 echo. echo 提示:避免多文件/文件夹同时压缩^^! echo. echo ( I 安装 / U 卸载 / Q 退出 ) echo. echo. set /p o=请输入: if /i "%o%"=="I" goto Install if /i "%o%"=="U" goto UnInstall if /i "%o%"=="Q" exit goto Page :Install reg add HKCR\*\shell\SanCAB菜单项 /v icon /t REG_SZ /d "iexpress.exe" /f>nul 2>nul reg add HKCR\*\shell\SanCAB菜单项 /v MUIVerb /t REG_SZ /d "SanCAB菜单" /f>nul 2>nul reg add HKCR\*\shell\SanCAB菜单项 /v SubCommands /t REG_SZ /d "SanCAB菜单压缩项;SanCAB菜单解压项" /f>nul 2>nul reg add HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\CommandStore\shell\SanCAB菜单压缩项 /ve /t REG_SZ /d "SanCAB压缩此文件" /f>nul 2>nul reg add HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\CommandStore\shell\SanCAB菜单压缩项 /v icon /t REG_SZ /d "iexpress.exe" /f>nul 2>nul reg add HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\CommandStore\shell\SanCAB菜单压缩项\command /ve /t REG_SZ /d "%SystemRoot%\system32\SanCAB.Bat %%1 FileSanCAB" /f>nul 2>nul reg add HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\CommandStore\shell\SanCAB菜单解压项 /ve /t REG_SZ /d "SanCAB解压此文件" /f>nul 2>nul reg add HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\CommandStore\shell\SanCAB菜单解压项 /v icon /t REG_SZ /d "iexpress.exe" /f>nul 2>nul reg add HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\CommandStore\shell\SanCAB菜单解压项\command /ve /t REG_SZ /d "%SystemRoot%\system32\SanCAB.Bat %%1 UnSanCAB" /f>nul 2>nul reg add HKCR\Directory\shell\SanCAB压缩文件夹 /v icon /t REG_SZ /d "iexpress.exe" /f>nul 2>nul reg add HKCR\Directory\shell\SanCAB压缩文件夹\command /ve /t REG_SZ /d "%SystemRoot%\system32\SanCAB.Bat %%1 SanCAB" /f>nul 2>nul reg query HKCR\Directory\shell\SanCAB压缩文件夹\command|FIND /i "SanCAB.Bat">nul||goto Admin copy /y "%~0" "%SystemRoot%\system32\SanCAB.Bat">nul 2>nul if not exist "%SystemRoot%\system32\SanCAB.Bat" goto Admin if /i "%~1"=="/reg" exit echo. echo. echo 安装成功,可在任意文件或目录上使用. echo. echo 按任意键退出... pause>nul exit :UnInstall reg delete HKCR\*\shell\SanCAB菜单项 /f>nul 2>nul reg delete HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\CommandStore\shell\SanCAB菜单压缩项 /f>nul 2>nul reg delete HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\CommandStore\shell\SanCAB菜单解压项 /f>nul 2>nul reg delete HKCR\Directory\shell\SanCAB压缩文件夹 /f>nul 2>nul reg query HKCR\Directory\shell\SanCAB压缩文件夹>nul 2>nul&&goto Admin del /s /q "%SystemRoot%\system32\SanCAB.Bat">nul 2>nul if exist "%SystemRoot%\system32\SanCAB.Bat" goto Admin echo. echo. echo 卸载成功,相关文件和右键菜单已删除. echo. echo 按任意键退出... pause>nul exit :Admin echo. echo. echo 操作失败,必须以右键管理员权限运行. echo. echo 按任意键退出... pause>nul exit |
发表回复