Really uexpected result of a script

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
Szecska
Posts: 17
Joined: 15 Aug 2019 15:29
Location: Hungary

Really uexpected result of a script

#1 Post by Szecska » 08 Oct 2019 11:42

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.
Last edited by Szecska on 08 Oct 2019 15:03, edited 2 times in total.

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Really uexpected result of a script

#2 Post by aGerman » 08 Oct 2019 12:17

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

pieh-ejdsch
Posts: 240
Joined: 04 Mar 2014 11:14
Location: germany

Re: Really uexpected result of a script

#3 Post by pieh-ejdsch » 08 Oct 2019 12:21

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

Szecska
Posts: 17
Joined: 15 Aug 2019 15:29
Location: Hungary

Re: Really uexpected result of a script

#4 Post by Szecska » 08 Oct 2019 15:10

Thaks for the replies!
Turns out Im an idiot, and I left out a second percent sign twice :oops: ...

Post Reply