Discussion forum for all Windows batch related topics.
Moderator: DosItHelp
-
nnnmmm
- Posts: 141
- Joined: 26 Aug 2017 06:11
#1
Post
by nnnmmm » 30 Aug 2017 01:55
Code: Select all
@ECHO OFF
SET K1=M:\AA.TXT
SetLocal EnableExtensions EnableDelayedExpansion
FOR /F "DELIMS=" %%V IN ('TYPE "%K1%"') DO (
SET VV=%%V
ECHO !VV:~0,1!
IF "!VV:~0,1!"=="%" ECHO DDDDDDDD
)
---------------------
AA.TXT has
%c1%\1.exe
%q1%\b.exe
ss.exe
dd.exe
why cant IF detect "%", while it echos correctly?
how can i solve?
-
penpen
- Expert
- Posts: 2009
- Joined: 23 Jun 2013 06:15
- Location: Germany
#2
Post
by penpen » 30 Aug 2017 02:42
The percentage sign is a special character that indicates that the following might be an environment variable.
In your case you are using the environment variable '
" ECHO DDDDDDDD' (without the outer single quotes).
But there is a way to escape a percentage sign (== using a replacement string for this character): '
%%'.
Code: Select all
IF "!VV:~0,1!"=="%%" ECHO DDDDDDDD
penpen