Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Problem setting variable under FOR loop.

6 views
Skip to first unread message

inetquestion

unread,
Aug 8, 2012, 11:36:37 PM8/8/12
to
when running the command below such as: test.bat res*stu*.pdf

Why does the for loop set the value of XXX, but in the next for loop it fails to set the value of 'attachment'?


============

@echo off

set XXX=
set attachment=

touch "resilxxoo stuff.pdf"

for %%I IN (%1) do set XXX="%%I"
echo Attachment-A: %XXX%


::::::::::::::::::::::::::::::::::::::
:: Process command line params
::::::::::::::::::::::::::::::::::::::
:while

IF "%1" == "" (GOTO wend)

If /I "%~x1" == ".pdf" (
for %%I in (%1) do set attachment="%%I"
echo 1: %1
echo Attachment-B: %attachment%
shift
)

@GOTO while
:wend

Harald Peters

unread,
Apr 22, 2014, 5:37:28 PM4/22/14
to
Op Thu, 09 Aug 2012 05:36:37 +0200 schreef inetquestion
<inetqu...@hotmail.com>:

> when running the command below such as: test.bat res*stu*.pdf
> Why does the for loop set the value of XXX, but in the next for loop it
> fails to set the value of 'attachment'?
> ============
> @echo off
> set XXX=
> set attachment=
> touch "resilxxoo stuff.pdf" <= is touch a util? internal cmd?
> for %%I IN (%1) do set XXX="%?%I" <= needs quotes? needs single % ?
> (quotes to enforce full names?)
> echo Attachment-A: %XXX%
> ::::::::::::::::::::::::::::::::::::::
> :: Process command line params
> ::::::::::::::::::::::::::::::::::::::
> :while
> IF "%1" == "" ?(GOTO wend)? <= needs brackets? needs then ?
> If /I "%~x1" == ".pdf" ( <= whats this
> var?
> for %%I in (%1) do set attachment="%?%I" <= needs
> quotes? needs single % ?
> echo 1: %1
> echo Attachment-B: %attachment%
> shift
> )
> @GOTO while
> :wend

>>> ms-dos has been awhile - just commenting <<<
--
Gemaakt met Opera's e-mailprogramma: http://www.opera.com/mail/
0 new messages