Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @Echo off
- ::: { Macro Definition
- Setlocal DisabledelayedExpansion
- (set \n=^^^
- %= This creates an escaped Line Feed - DO NOT ALTER =%
- )
- ::: [ For Loop Constructor macro. ] For advanced programmers who need to use dynamic for loop options during code blocks.
- ::: - usage: %n.For%{For loop options}{variable set}{For Metavariable}{commands to execute}
- ::: - use delayed !and! variable to construct concatenated commands in the new for loop.
- Set n.For=For %%n in (1 2) Do If %%n==2 (%\n%
- Set FOR=%\n%
- For /F "tokens=1,2,3,4 Delims={}" %%1 in ("!mac.in!") Do (%\n%
- Set "FOR=For /F %%1 %%3 in ("!%%2!") Do (%%~4)"%\n%
- )%\n%
- Call :Exc.For%\n%
- )Else Set mac.in=
- Set "and.=&&"
- Set "and=!and.!"
- ::: } End macro definition.
- Setlocal EnableDelayedExpansion& rem // required to expand n.For constructor macro
- ::: - Usage examples:
- Set "example=is a string line"
- %n.For%{"tokens=* delims="}{example}{%%G}{Echo/%%~G}
- %n.For%{"tokens=1,2,3,4 delims= "}{example}{%%G}{"Echo/%%~J %%~G %%~H %%~I !and! Echo/%%~I %%~G %%~H %%~J"}
- Set "example2=Code block example"
- For %%a in (1 2 3) do (
- %n.For%{"Tokens=%%a Delims= "}{example2}{%%I}{"For /L %%# in (1 1 4) Do (Set %%I[%%#]=%%a%%#) !and! Set %%I[%%#]"}
- )
- Pause > Nul
- Goto :EOF
- :Exc.For
- %FOR%
- Exit /B
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement