Post by Kenny McCormackPost by Tom Del RossoPost by Harry PotterWere these batch files useful to anybody? I am an egotist and desire feedback. :)
:-)
OK. Complete batch files are probably useful only to their creator,
but subroutines and techniques are adaptable.
This is an excellent observation. I have long said (in the Unix/Linux
context, but the principle is the same): Nobody wants to run other
people's shell scripts.
As you say, the ideas and techniques are sharable, but whole scripts
are rarely going to be useful (and, more importantly, safe) for other
people to use.
I routinely use a few that would be dangerous for anyone who didn't
understand them, but I've written some that would be useful to a few
others.
Here is a demo of a technique I haven't seen elsewhere.
@echo off
rem ******************************************************
rem You can have 88 consecutive "FOR variables" from
rem character 38 [&] to character 125 [}] inclusive,
rem or 93 if you start at character 33 [!] and don't
rem use the unusable character 37 [%].
rem
rem This takes advantage of the fact that FOR variables
rem can be reassigned within a block as "(" and "F"
rem and "d" are below. This is necessary because the
rem maximum "tokens=" is 31 in a single FOR command.
rem
rem Most of the control characters work, but you can't
rem type them in most editors. Generating a batch with
rem the binary values shows that they work
rem except 9, 10, 11, 12, 13, 26, and of course 32.
rem
rem Curiously, 20 and 21 work separately
rem but tokens=20-21 or tokens=20,21 doesn't work,
rem so it looks like you can't use "tokens=20,*" either.
rem
rem Also, 44 [,] 59 [;] and 61 [=] work as references
rem but not as the base variable in the FOR line. For
rem example those 3 can be used like this:
rem for /f "tokens=1,2" %%^+ in ("text1 TEXT2") do (
rem echo Character 43 [^+] Token 1 [%%^+]
rem echo Character 44 [^,] Token 2 [%%^,]
rem )
rem for /f "tokens=1,2" %%^: in ("text1 TEXT2") do (
rem echo Character 58 [^:] Token 1 [%%^:]
rem echo Character 59 [^;] Token 2 [%%^;]
rem )
rem for /f "tokens=1,2" %%^< in ("text1 TEXT2") do (
rem echo Character 60 [^<] Token 1 [%%^<]
rem echo Character 61 [^=] Token 2 [%%^=]
rem )
rem All others below work in the FOR line.
rem ******************************************************
rem generate a sting of numbers to be used by other FOR commands
set "text="
for /L %%a in (1,1,256) do call set text=%%text%% %%a
echo %text%
echo.
echo Starting with BEL (ASCII 7) as FOR variable:
for /f "tokens=7" %%^. in ("%text%") do (
for /f "tokens=15" %%^€ in ("%text%") do (
for /f "tokens=20" %%^¶ in ("%text%") do (
for /f "tokens=21" %%^§ in ("%text%") do (
echo Character 7 [^.] Token 7 [%%^.]
echo Character 15 [^€] Token 15 [%%^€]
echo Character 20 [^¶] Token 20 [%%^¶]
echo Character 21 [^§] Token 21 [%%^§]
)
)
)
)
echo --------------------------------
echo Starting with ! as FOR variable:
for /f "tokens=1-7,*" %%! in ("%text%") do (
for /f "tokens=1-30,*" %%( in ("%%(") do (
for /f "tokens=1-30,*" %%F in ("%%F") do (
for /f "tokens=1-30" %%d in ("%%d") do (
echo Character 33 [!] Token 1 [%%!]
echo Character 34 ["] Token 2 [%%"]
echo Character 35 [#] Token 3 [%%#]
echo Character 36 [$] Token 4 [%%$]
echo Character 37 [^%] Token 5 [%%^%]
echo Character 38 [^&] Token 6 [%%^&]
echo Character 39 ['] Token 7 [%%']
echo Character 40 [^(] Token 8 [%%^(]
echo Character 41 [^)] Token 9 [%%^)]
echo Character 42 [*] Token 10 [%%*]
echo Character 43 [+] Token 11 [%%+]
echo Character 44 [,] Token 12 [%%,]
echo Character 45 [-] Token 13 [%%-]
echo Character 46 [.] Token 14 [%%.]
echo Character 47 [/] Token 15 [%%/]
echo Character 48 [0] Token 16 [%%0]
echo Character 49 [1] Token 17 [%%1]
echo Character 50 [2] Token 18 [%%2]
echo Character 51 [3] Token 19 [%%3]
echo Character 52 [4] Token 20 [%%4]
echo Character 53 [5] Token 21 [%%5]
echo Character 54 [6] Token 22 [%%6]
echo Character 55 [7] Token 23 [%%7]
echo Character 56 [8] Token 24 [%%8]
echo Character 57 [9] Token 25 [%%9]
echo Character 58 [:] Token 26 [%%:]
echo Character 59 [;] Token 27 [%%;]
echo Character 60 [^<] Token 28 [%%^<]
echo Character 61 [=] Token 29 [%%=]
echo Character 62 [^>] Token 30 [%%^>]
echo Character 63 [?] Token 31 [%%?]
echo Character 64 [@] Token 32 [%%@]
echo Character 65 [A] Token 33 [%%A]
echo Character 66 [B] Token 34 [%%B]
echo Character 67 [C] Token 35 [%%C]
echo Character 68 [D] Token 36 [%%D]
echo Character 69 [E] Token 37 [%%E]
echo Character 70 [F] Token 38 [%%F]
echo Character 71 [G] Token 39 [%%G]
echo Character 72 [H] Token 40 [%%H]
echo Character 73 [I] Token 41 [%%I]
echo Character 74 [J] Token 42 [%%J]
echo Character 75 [K] Token 43 [%%K]
echo Character 76 [L] Token 44 [%%L]
echo Character 77 [M] Token 45 [%%M]
echo Character 78 [N] Token 46 [%%N]
echo Character 79 [O] Token 47 [%%O]
echo Character 80 [P] Token 48 [%%P]
echo Character 81 [Q] Token 49 [%%Q]
echo Character 82 [R] Token 50 [%%R]
echo Character 83 [S] Token 51 [%%S]
echo Character 84 [T] Token 52 [%%T]
echo Character 85 [U] Token 53 [%%U]
echo Character 86 [V] Token 54 [%%V]
echo Character 87 [W] Token 55 [%%W]
echo Character 88 [X] Token 56 [%%X]
echo Character 89 [Y] Token 57 [%%Y]
echo Character 90 [Z] Token 58 [%%Z]
echo Character 91 [[] Token 59 [%%[]
echo Character 92 [\] Token 60 [%%\]
echo Character 93 []] Token 61 [%%]]
echo Character 94 [^^] Token 62 [%%^^]
echo Character 95 [_] Token 63 [%%_]
echo Character 96 [^`] Token 64 [%%^`]
echo Character 97 [a] Token 65 [%%a]
echo Character 98 [b] Token 66 [%%b]
echo Character 99 [c] Token 67 [%%c]
echo Character 100 [d] Token 68 [%%d]
echo Character 101 [e] Token 69 [%%e]
echo Character 102 [f] Token 70 [%%f]
echo Character 103 [g] Token 71 [%%g]
echo Character 104 [h] Token 72 [%%h]
echo Character 105 [i] Token 73 [%%i]
echo Character 106 [j] Token 74 [%%j]
echo Character 107 [k] Token 75 [%%k]
echo Character 108 [l] Token 76 [%%l]
echo Character 109 [m] Token 77 [%%m]
echo Character 110 [n] Token 78 [%%n]
echo Character 111 [o] Token 79 [%%o]
echo Character 112 [p] Token 80 [%%p]
echo Character 113 [q] Token 81 [%%q]
echo Character 114 [r] Token 82 [%%r]
echo Character 115 [s] Token 83 [%%s]
echo Character 116 [t] Token 84 [%%t]
echo Character 117 [u] Token 85 [%%u]
echo Character 118 [v] Token 86 [%%v]
echo Character 119 [w] Token 87 [%%w]
echo Character 120 [x] Token 88 [%%x]
echo Character 121 [y] Token 89 [%%y]
echo Character 122 [z] Token 90 [%%z]
echo Character 123 [{] Token 91 [%%{]
echo Character 124 [^|] Token 92 [%%^|]
echo Character 125 [}] Token 93 [%%}] works up to here
echo Character 126 [~] Token 94 [%%~] doesn't work from here
forward
echo Character 127 [Š] Token 95 [%%Š]
echo Character 128 [Ç] Token 96 [%%Ç]
echo Character 129 [ü] Token 97 [%%ü]
echo Character 130 [é] Token 98 [%%é]
)
)
)
)
pause