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
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.
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.
Summary: Hi all, I am asking a question using the SET command within a batch file using Windows XP Pro SP3 and need to know how to detect if nothing is entered - for example, if the user simply presses the Ent...
Summary: Well first of all let me say that couldn't agree more with your statement. Second of all I could acomplish that without FOR /L Like this SET /p you=Do you like cheese? y/n If %you%==n ECHO You Suck! ...
Summary: Is there a way to include multiple sets (both positive and negative) in one variable inside of a for /r loop? Here's the command I'm using: for /r %%i in (*.shp) do copy "%%i" "%%~pni_wgs.shp" /-Y But...