FOR /L loop using set command

April 19, 2009 at 01:39:17
Specs: Windows XP
I am throwing things at this point trying to figure out why I can not set variables inside of my for /l counter. Here is the snippet that doesn't work :

set /p startdate=Enter the Start date for log retrieval (Format: yyyymmdd)=
set /p enddate=Enter the End date for log retrieval (Format: yyyymmdd)=

FOR /L %%d IN (%startdate%,1,%enddate%) DO (
set /a juld = %%d
set /a jd = %juld%
set /a jyear= %jd:~0,1%
set /a jyear=%jyear%
set jdays= %jd:~1,3%

more code is here but the initial %%d value is not getting set to the variable. Yes, I am new to batch programming and there definitely could be something I am missing. I have tried the delayed variable expansion and so forth but nothing seems to work.


See More: FOR /L loop using set command

Report •


#1
April 19, 2009 at 04:00:35
setlocal EnableDelayedExpansion
FOR /L %%d IN (%startdate%,1,%enddate%) DO (
  set juld=%%d
  set jd=!juld!
  set jyear=!jd:~0,1!
  set jyear=!jyear!
  set jdays=!jd:~1,3!


The delayed expansion acts on variables marked by ! not the usual %. Never insert spaces before and after the = in SET statement. The /A switch is required for arithmetics only not just numeric assignments.

Report •

#2
April 19, 2009 at 04:14:03
Content removed by Valerie - beaten to the punch again.

Report •

#3
April 20, 2009 at 09:00:07
I don't see the pointf of there, but I'll stay tuned:

set juld=%%d
set jd=!juld!
set jyear=!jyear!


=====================================
If at first you don't succeed, you're about average.

M2


Report •

Related Solutions


Ask Question