Hi I have a script I made using information on this page.
I realize that running two separate batch files (:SetVar
and:Brains
) will work but when I try to combine the two into one It doesn't work.
I'd be happy if anyone can explain to me why mine does not work and show me what I can do to make mine work.
:SetVar
Brains "Hello" "Goodbye" "input.txt" > "newfile.txt"
GOTO :Brains
:Brains
SETLOCAL ENABLEEXTENSIONS
SETLOCAL DISABLEDELAYEDEXPANSION
if "%~1"=="" findstr "^::" "%~f0"&GOTO:EOF
for /f "tokens=1,* delims=]" %%A in ('"type %3|find /n /v """') do (
set "line=%%B"
if defined line (
call set "line=echo.%%line:%~1=%~2%%"
for /f "delims=" %%X in ('"echo."%%line%%""') do %%~X
) ELSE echo.
)
PAUSE
When I use the Call command:
call :SetVar
call :Brains
goto :eof
pause
:SetVar
:Brains "Hello" "Goodbye" "input.txt" > "newfile.txt"
goto :eof
:Brains
SETLOCAL ENABLEEXTENSIONS
SETLOCAL DISABLEDELAYEDEXPANSION
if "%~1"=="" findstr "^::" "%~f0"&GOTO:EOF
for /f "tokens=1,* delims=]" %%A in ('"type %3|find /n /v """') do (
set "line=%%B"
if defined line (
call set "line=echo.%%line:%~1=%~2%%"
for /f "delims=" %%X in ('"echo."%%line%%""') do %%~X
) ELSE echo.
)
goto :eof
I get no error but I get:
C:\Users\MALKAVIAN\Batch files\change words in file>CALL :SetVar
C:\Users\MALKAVIAN\Batch files\change words in file>goto :eof
C:\Users\MALKAVIAN\Batch files\change words in file>CALL :Brains
C:\Users\MALKAVIAN\Batch files\change words in file>goto :eof
C:\Users\MALKAVIAN\Batch files\change words in file>pause
Press any key to continue . . .