Announcement

Collapse
No announcement yet.

How can I stop this script from removing double percents and replacing with 1

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • How can I stop this script from removing double percents and replacing with 1

    the original thread and post is above

    p=114492

    code is as follows

    Code:
    @echo off
    SET Word="pause"
    FOR %%b in (%1) DO ( SET Word=%1 )
    setlocal enabledelayedexpansion
     
    FOR /F "usebackq delims=" %%G IN ("build.bat") DO (
     Set Line=%%G
     Set Line=!Line:"='!
      Call:replace "!Line!"
    )
    goto:eof ------------
     :replace subroutine
     (Set Line=%*&Set Line=!Line:~1,-1!)
     Set Line=!Line:'="!
     Set "Line=!Line:pause=!"
     echo.!Line! >>"BuildModified.bat"
    goto:eof ------------
    Works like a charm in removing any pauses in the bat files that I am running BUT the most of the bat files also have this line:

    FOR /R BUILD %%d IN (.SVN) DO @RD /S /Q "%%d" 2>NUL
    which gets trunctated to:
    "FOR /R BUILD %d IN (.SVN) DO @RD /S /Q "%d" 2>NUL

    Which kills the script dead


    What can I change in the above code to put back both %%?
    I know this is an old subject but I really need this help.
    Last edited by Rems; 1st November 2010, 09:04. Reason: added [post] tags around the postnumber

  • #2
    Re: How can I stop this script from removing double percents and replacing with 1

    It is a known issue with batches, therefore it is better to use SED for Windows or use a vbscript for replacing strings.

    Or, try this batch,
    Code:
    @echo off & SETLOCAL ENABLEEXTENSIONS
    
    Set "file=build.bat"
    SET "Word=%~1"
    
    color 6A & echo please wait.. & title parsing file, "%file%"
    
    call:BatchSubstitude "%file%" > "BuildModified.bat"
    
    rem MOVE /Y "BuildModified.bat" "%file%"
    
    
    goto:eof ------------
    :BatchSubstitude *** source http://www.dostips.com/?t=Batch.FindAndReplace
       SETLOCAL DISABLEDELAYEDEXPANSION
       for /f "tokens=1,* delims=]" %%A in ('"type "%~1"|find /n /v """') do (
         set "line=%%B"
         if defined line (
             call:replace "%Word%" ""
    
             call set "line=echo.%%line%%"
             for /f "delims=" %%* in ('"echo."%%line%%""') do (%%~*)
         ) ELSE (echo.))
       ENDLOCAL
       exit /b 0
       :replace
       >nul 2>&1 (
       call set line |Findstr.exe /RIC:"\<%~1\>" && call set line |Findstr.exe /RIVC:"\<@%~1\>" && call set "line=%%line:%~1=%~2%%")
    exit /b 0
    goto:eof ------------
    \Rems


    EDIT,
    simuler thread: http://forums.petri.com/showthread.p...701#post217701
    Last edited by Rems; 1st November 2010, 11:46.

    This posting is provided "AS IS" with no warranties, and confers no rights.

    __________________

    ** Remember to give credit where credit's due **
    and leave Reputation Points for meaningful posts

    Comment

    Working...
    X