Page 1 of 1

Really uexpected result of a script

Posted: 08 Oct 2019 11:42
by Szecska
Hello everyone!

I have a really annoying problem on hand witha really short script:

Code: Select all

set me=%~nx0
echo a
for /f "tokens=*" %%G in ('dir "%~dp0" /b') do (
echo b
if not %G == "%me%" (
echo c
if %~zG == 32640 (echo %G    %~zG b OK) else echo %G   %~zG b MISMATCH
) )
pause
It shows a sytax error at the line 'if not %G == %me% (' , and phrase somehow like this: 'if not ==me" ('
I have no idea to how to correct this, since I dont know the cause of the problem :( :cry:

I would appreciate any help
Thanks in advance
Szecska

Edit:Thanks for the replies!
Yep Steffen you were right %G is not defined, but in the original script it was written correctly,so I corrected here too.
Its the variable of the for loop. And this is the whole script and not just a chunk.

Re: Really uexpected result of a script

Posted: 08 Oct 2019 12:17
by aGerman
Where does %G come from? It should be either %G% (if you defined this variable somewhere else) or %%U if you meant the FOR variable.
Also remove the spaces around the == operator and consider to compare quoted strings at both sides of the ==.

Steffen

Re: Really uexpected result of a script

Posted: 08 Oct 2019 12:21
by pieh-ejdsch
Hello Szecska,

You want to try a Variable of for loop.
Then take %%U or %%~U or %%~zU.
The output from the dir command is without quotes, so they should be used on both sides in comparison.

Phil

Re: Really uexpected result of a script

Posted: 08 Oct 2019 15:10
by Szecska
Thaks for the replies!
Turns out Im an idiot, and I left out a second percent sign twice :oops: ...