获取hex值的原理参考了 lxmxn 的 表示感谢
http://www.cn-dos.net/forum/viewthread.php?tid=26521&fpage=1&highlight=CMD%E6%89%B9%E5%A4%84%E7%90%86%E8%8E%B7%E5%8F%96%E6%96%87%E4%BB%B6%E7%9A%84ASCII%E7%A0%81
最大支持 。由于10k的文件在编码时速度就已经很慢了,所以也不
想在扩充了。其实简单的修改一下代码就可支持大于64k的文件了,有兴趣的朋
友可以自己扩充一下。
如果对大文件进行处理还是建议采用高级语言编写的Exe2Bat
这段代码仅作为一个演示,如果首次编码出现问题请再次运行即可
:: Code by-q8249014 CMD@XP Exe2Bat.cmd
:: update 2010-1-8
@echo off&endlocal&setlocal enabledelayedexpansion
set /a "count=0,str=240,var=%random%%%10"
set "hx=0123456789ABCDEF"
set /p file=请输入文件的绝对路径 :&cls
for /f "eol=? delims=" %%i in ("!file!") do (if not exist "%%~$:i.\*" (
set "expname=%%~xi"&set /a "size=%%~zi-1"))
if not defined size echo.输入错误?&%0
if %size% NEQ -1 (if 65279 LSS %size% echo.文件太大了!&%0) else (echo.0 字节?&%0)
2>nul del /a /q /f cmp_.ps
>nul fsutil file createnew "%~dp0cmp_.ps" %size%
>>"%~dp0cmp_.ps" <nul set/p"=%var%"
(echo.@echo off
echo.^>nul ^(chcp 437^&graftabl 936^)
echo.more +6 %%0^|debug
echo.2^>nul del /a /q /f new_%expname%^&ren tmp_ new_%expname%
echo.pause
echo.exit/b)>"%~dp0test_.bat"
set "file=!file:"=!"
echo.正在对文件进行编码,请稍后…………&echo.
(for /f "skip=1 tokens=1,3 delims=: " %%i in ('fc /b "%~dp0cmp_.ps" "!file!"') do (
set /a "offset=0x%%i,newline=count&15"
if !newline! EQU 0 call :Dxh
if !offset! EQU !count! (<nul set /p"= %%j") else (
set /a addzero=offset-count
for /l %%i in (1 1 !addzero!) do (
<nul set /p"= 00"
set /a "count+=1,newline=count&15"
if !newline! EQU 0 call :Dxh)
<nul set /p"= %%j")
set /a count+=1
)
echo.)>>"%~dp0test_.bat"
2>nul del /a /f cmp_.ps
set /a str=size-15
set "data=rcx ^!h^! "n tmp_" w q"
:Dxh
set /a str+=16
set h=
(for /l %%i in (1 1 8) do (
if !str! GTR 0 (
set /a "n=str&15,str>>=4"
call set h=%%hx:~!n!,1%%!h!
)
)
set str=%str%)
(for %%i in (%data%) do (>>"%~dp0test_.bat" echo.%%~i))&&goto :End
if %count% neq 0 echo.
<nul set /p"=e %h%"
goto :eof
:End
echo.文件编码成功!
echo.
echo.新文件绝对路径:%~dp0test_.bat
echo.
pause
exit/b
Last edited by q8249014 on 2010-1-9 at 21:12 ]