Computing.Net > Forums > Programming > FOR /L loop using set command

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

FOR /L loop using set command

Reply to Message Icon

Name: mattbradley
Date: April 19, 2009 at 01:39:17 Pacific
OS: Windows XP
Subcategory: Batch
Comment:

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.



Sponsored Link
Ads by Google

Response Number 1
Name: IVO
Date: April 19, 2009 at 04:00:35 Pacific
Reply:

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.

0

Response Number 2
Name: Valerie (by Garibaldi)
Date: April 19, 2009 at 04:14:03 Pacific
Reply:

Content removed by Valerie - beaten to the punch again.


0

Response Number 3
Name: Mechanix2Go
Date: April 20, 2009 at 09:00:07 Pacific
Reply:

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


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: FOR /L loop using set command

Detect 'Enter' using SET command? www.computing.net/answers/programming/detect-enter-using-set-command/17365.html

For /l www.computing.net/answers/programming/for-l/17302.html

Help with For /r loop www.computing.net/answers/programming/help-with-for-r-loop/19281.html