JSI Tip 1230. The "FOR /L" command.


FOR /L %variable IN (start,step,end) DO command \[command-parameters\]

Performs the command from Start, by step, through end such that:

FOR /L %i in (1,1,3) do @echo %i                would echo:
1
2
3

and                 FOR /L %i in (2,-1,-2) do @echo %i                would echo:
2
1
0
-1
-2

I use this techique to copy these tips from their on-line folder to the Desktop Tips folder:

DESKTOP 1190 1229

copies tips 1190 through 1229, and tip index 1100 and 1200, without the advertising banner.  DESKTOP.BAT contains:


@echo off
if "%2"

"" goto dumbdumb if "%1" GTR "%2" goto dumbdumb setlocal set prev=999999 for /l %%i in (%1,1,%2) do call :Build %%i endlocal goto end :dumbdumb @echo DESKTOP From To goto end :Build set tip=%1 set /a num=%tip% set /a num=%num% + 10000 set /a num=%num% / 100 set /a num=%num% * 100 set num=%num% set num=%num:~1,4% if "%num%"

"%prev%" goto dettip set prev=%num% :dettip :end
Hide comments

Comments

  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
Publish