对于获取 ASCII 全范围(0x00 -- 0xFF)字符, 本论坛上原本就有一篇由 plp626 所发:
扩展ASCII码字符集0x00~0xff 批处理获取函数
http://www.bathome.net/viewthread.php?tid=12347
本帖转载 dostips 上不同方式的实现
http://www.dostips.com/forum/viewtopic.php?f=3&t=5326
原文标题:
"Create nul and all ascii characters with only batch"
-- 译: 只用批处理生成 nul 和所有 ASCII 字符
其实 NUL (码值: 0) 也是一个 ASCII 字符, 只是由于它的特殊性和处理上的困难, 所以作者特别强调了一下吧.
先贴出两个提速稳定版: carlos 版 和 dbenham 版, 最后再贴出一个初始稳定版.
关于代码的详细说明, 请阅读 dostips 原帖, 转载到此, 主要为备份之用.
carlos 提速稳定版: | @echo off | | | | :gen255 | | ::generates 0-255 .chr files that have 1 byte | | ::Teamwork of carlos, penpen, aGerman, dbenham, einstein1969 | | ::Tested under Win8, WinXP(64mb) | | setlocal enableextensions disabledelayedexpansion | | set "map=paddingpaddingpaddingpaddingpadding" | | set "map=%map%#$%%&'()*+,-./0123456789:;<p>?@" | | set "map=%map%ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`" | | set "map=%map%abcdefghijklmnopqrstuvwxyz{|}~" | | set "map=%map: =%" | | set "gchr=(type nul >%%#.tmp" | | set "gchr=%gchr% & makecab /d compress=off" | | set "gchr=%gchr% /d reserveperfoldersize=%%#" | | set "gchr=%gchr% /d reserveperdatablocksize=26" | | set "gchr=%gchr% %%#.tmp %%#.chr 1>nul" | | set "gchr=%gchr% & type %%#.chr" | | set "gchr=%gchr% |((for /l %%_ in (1 1 38) do pause) 1>nul" | | set "gchr=%gchr% & findstr ^^^^ 1>%%#.tmp)" | | set "gchr=%gchr% & copy /y %%#.tmp /a %%#.chr /b 1>nul" | | set "gchr=%gchr% & del %%#.tmp)" | | set "gmap=for /l %%# in (35 1 126) do" | | set "gmap=%gmap% set /p "=!map:~%%#,1!" 0<nul 1>%%#.chr" | | set "new_thread=start /i /w /b cmd /a /q /d /c" | | if exist ???.chr del /a /f /q ???.chr | | %new_thread% "for /l %%# in (127 1 169) do %gchr%" | | %new_thread% "for /l %%# in (170 1 211) do %gchr%" | | %new_thread% "for /l %%# in (212 1 255) do %gchr%" | | for /l %%# in (0 1 34) do %gchr% | | cmd /a /v:on /q /d /c "%gmap%" | | :gen255w | | ping -l 0 -n 1 -w 100 1.0.0.0 >nul | | for %%# in (169.chr 211.chr 255.chr) do ( | | if not exist %%# goto :gen255w | | if not "1"=="%%~z#" goto :gen255w) | | for %%# in (61) do %gchr% | | copy /y nul + nul /a 26.chr /a 1>nul | | goto :eofCOPY |
dbenham 提速稳定版: | @echo off | | setlocal | | | | :genAllChr | | ::This code creates 256 1 byte files, one for each possible byte value. | | ::This is encoded in a macro way to be called asynchronously with start cmd /c | | ::Teamwork of carlos, penpen, aGerman, dbenham, einstein1969 | | ::Tested under Win7 and XP | | set ^"genchr=(^ | | for /l %%N in (%%A !cnt! 255) do (^ | | if %%N equ 26 (^ | | copy /y nul + nul /a 26.chr /a ^>nul^ | | ) else (if %%N geq 35 if %%N leq 126 if %%N neq 61 (^ | | ^<nul set /p "=!ascii:~%%N,1!" ^>%%N.chr^ | | ))^&^ | | if not exist %%N.chr (^ | | makecab /d compress=off /d reserveperdatablocksize=26 /d reserveperfoldersize=%%N %%A.tmp %%N.chr ^>nul^&^ | | type %%N.chr ^| ((for /l %%n in (1 1 38) do pause)^>nul^&findstr "^^" ^>%%N.temp)^&^ | | ^>nul copy /y %%N.temp /a %%N.chr /b^&^ | | del %%N.temp^ | | )^ | | ))^&^ | | del %%A.tmp^" | | del /f /q /a *.chr >nul 2>&1 | | set "ascii= #$%%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~" | | set /a cnt=number_of_processors | | if %cnt% lss 1 set cnt=1 | | if %cnt% gtr 256 set cnt=256 | | set /a "end=cnt-1" | | for /l %%A in (0 1 %end%) do ( | | type nul >%%A.tmp | | if %%A equ %end% ( | | cmd /q /v:on /c "%genchr%" | | ) else ( | | start "" /b cmd /q /v:on /c "%genchr%" | | ) | | ) | | :genAllChr.check | | for /l %%N in (0 1 %end%) do if exist %%N.tmp goto :genAllChr.check | | exit /bCOPY |
初始稳定版: | | | | | | | @echo off | | setlocal EnableDelayedExpansion | | 2>nul md "characters" | | pushd "characters" | | | | >"t.tmp" type nul | | set "hex=0 1 2 3 4 5 6 7 8 9 A B C D E F" | | for %%A in (%hex%) do for %%B in (%hex%) do ( | | set /a "N=0x%%A%%B" | | >nul makecab /d compress=off /d reserveperfoldersize=!N! /d reserveperdatablocksize=26 "t.tmp" "%%A%%B.chr" | | type "%%A%%B.chr" | ((for /l %%N in (1 1 38) do pause)>nul&findstr "^">"temp.tmp") | | >nul copy /y "temp.tmp" /a "%%A%%B.chr" /b | | ) | | >nul copy /y nul + nul /a "1A.chr" /a | | del "t.tmp" "temp.tmp" | | popdCOPY |
|