need some corrections of processing a batch for "!" for DelayedExpansion

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
nnnmmm
Posts: 162
Joined: 26 Aug 2017 06:11

need some corrections of processing a batch for "!" for DelayedExpansion

#1 Post by nnnmmm » 02 Oct 2024 22:05

if a website has a symbol "!" in it, this batch does not work on that website selection
possible to correct the code?

F9-WEBSITE.TXT has
http://www.dynamoo.com/technical/ebcdic.htm
-
https://www.dnsstuff.com/
http://www.ztw3.com/forum/forum.php
http://truebasic.com/forum
-
ftp://ftp.mcafee.com/pub/antivirus/datfiles/4.x
http://www.google.com/advanced_search?n ... =&ie=UTF-8
https://www.dict.cc/?s=Matrose!
http://www.hot-keyboard.com/
http://www.mscd.edu/~mdl/gerresources/A.htm
----------------------------------------------------------------

Code: Select all

@ECHO OFF
SET P1=C:\firefox.exe
SET K1=M:\F9-WEBSITE.TXT

SET DS1=0
SET DS2=75
REM *********************************************************************
ECHO %K1%
ECHO.
SetLocal EnableExtensions EnableDelayedExpansion

SET CC=0
FOR /F "DELIMS=" %%V IN ('TYPE "%K1%"') DO (
   SET /A CC=!CC!+1

   IF !CC! GEQ 1 IF !CC! LEQ 9 SET DD= !CC!
   IF !CC! GTR 9 SET DD=!CC!

   SET VV=%%V
   SET C1=0
   IF /I "!VV:~0,1!"=="-" (
      SET /A CC=!CC!-1
      SET C1=1
      ECHO.
   )
   IF /I "!VV:~0,10!"=="http://www"  (SET C1=1)&(ECHO !DD! !VV:~11,%DS2%!)
   IF /I "!VV:~0,11!"=="https://www" (SET C1=1)&(ECHO !DD! !VV:~12,%DS2%!)
   IF /I "!VV:~0,9!"=="ftp://ftp"    (SET C1=1)&(ECHO !DD! !VV:~10,%DS2%!)
   IF /I "!C1!"=="0"                            (ECHO !DD! !VV:~7,%DS2%!)

   IF !CC! EQU 40 GOTO :SCREEN_FULL
)
:SCREEN_FULL

REM ----------------------------------
ECHO.
SET    VAR=DUMMY
SET /P "VAR=INPUT: "
IF %VAR%==DUMMY GOTO :END1
ECHO.

SET CC=0
FOR /F "DELIMS=" %%U IN ('TYPE %K1%') DO (
   SET /A CC=!CC!+1
   SET UU=%%U
   IF /I "!UU:~0,1!"=="-" SET /A CC=!CC!-1
   IF /I NOT "!UU:~0,1!"=="-" IF !VAR!==!CC! (
      SetLocal EnableExtensions DisableDelayedExpansion
      %P1% %%U
      EndLocal
      GOTO :END
   )
)

:END1
:END

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

Re: need some corrections of processing a batch for "!" for DelayedExpansion

#2 Post by pieh-ejdsch » 03 Jan 2025 13:58

When set the Variables with "!" - you need to turn of delayedExpansion.
Otherwise you won't have any exclamation marks in the variable.

Code: Select all

@ECHO OFF
SetLocal EnableExtensions disableDelayedExpansion
SET  P1=C:\firefox.exe
SET  K1=D:\a\F9-WEBSITE.TXT
set "lineC="
REM *********************************************************************
ECHO %K1%
ECHO.
SET  /a "CC =DS1 =0, DS2 =75, scr =8"
FOR /F "DELIMS=" %%V IN ('TYPE "%K1%"') DO (
   SET VV=%%V
   (
      for /f "delims=-" %%a in ("%%V") do (
         SET /A "LineC =1000 +(CC +=1)"
         if ! GTR ' setlocal enabledelayedexpansion
         IF !CC! LEQ 9 SET CC= !CC!
         IF /I       "!VV:~0,11!"=="https://www"  ECHO !CC! !VV:~12,%DS2%!
         IF /I       "!VV:~0,10!"=="http://www" ( ECHO !CC! !VV:~11,%DS2%!
         ) else IF /I "!VV:~0,7!"=="http://"      ECHO !CC! !VV:~7,%DS2%!
         IF /I        "!VV:~0,9!"=="ftp://ftp"    ECHO !CC! !VV:~10,%DS2%!
         for %%n in (!LineC!) do (
            if ! lss ' endlocal
            set "Line_%%n=%%V"
            2>nul set /a "x /=(cc %%scr)" || call :SCREEN_FULL
   )  )  ) || echo(
)
set "scr=... fine"
if defined LineC call :SCREEN_FULL
pause
exit/b

:SCREEN_FULL
REM ----------------------------------
ECHO.
SET /P "VAR=INPUT: " || echo next %scr% ... && exit /b
ECHO.
set /a "Input =1000 +Var"
for %%n in (%Input%) do (
   for /f "delims== tokens=1*" %%b in ('set Line_%%n') do %p1% %%c
)
set "lineC="
exit /b

Post Reply