Discussion:
Problem setting variable under FOR loop.
(too old to reply)
inetquestion
2012-08-09 03:36:37 UTC
Permalink
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
2014-04-22 21:37:28 UTC
Permalink
Op Thu, 09 Aug 2012 05:36:37 +0200 schreef inetquestion
Post by inetquestion
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/
Loading...