I'd suggest to keep your original post original and place updates in a reply/comment. Otherwise, people might get confused about the article. Just a friendly tip
Based on your current update of this article, I've created and tested some code.
Below I've adjusted your code a bit to make it work with the other code I made.
Notice the REM statements, I've used them as start and end markers to find the requested code:
Code: Select all
@echo off
echo Type 1 for Super Mario 64, type 2 for Ocarina of Time, type 3 for Majora's Mask
set /p input=
if %input%==1 goto Game1
if %input%==2 goto Game2
if %input%==3 goto Game3
REM Game1 start
:Game1
cd "C:\Users\Giovanni\Desktop\Emuladores\Nintendo 64\---"
start Project64.exe "C:\Users\Giovanni\Desktop\Emuladores\Nintendo 64\Roms\Super Mario 64 (USA).z64"
exit
REM Game1 end
REM Game2 start
:Game2
cd "C:\Users\Giovanni\Desktop\Emuladores\Nintendo 64\---"
start Project64.exe "C:\Users\Giovanni\Desktop\Emuladores\Nintendo 64\Roms\Legend of Zelda, The - Ocarina of Time (USA).n64"
exit
REM Game2 end
REM Game3 start
:Game3
cd "C:\Users\Giovanni\Desktop\Emuladores\Nintendo 64\---"
start Project64.exe "C:\Users\Giovanni\Desktop\Emuladores\Nintendo 64\Roms\Legend of Zelda, The - Majora's Mask (USA).z64"
exit
REM Game3 end
Here is the code that removes the parts you requested.
I've put it into functions for reusability.
Function labelList lists labels in a batch script and puts them into a return variable.
Function filterScript filters out the requested code.
Code: Select all
@echo off
call:filterScript "subject.cmd" "Game3" "subject2.cmd"
exit /b
:filterScript Script Marker [Output]
setlocal enableDelayedExpansion
call:labelList "%~f1" filterScript.Labels
for /f "tokens=1,* delims=:" %%b in (
'findstr /rbinc:".*" "%~f1"'
) do (
for /f "tokens=1,* delims=:" %%d in (
'echo("%%~c"^|findstr /ric:"REM %~2 start"'
) do (
if "!MarkerStart!" equ "" set "MarkerStart=%%b"
)
for /f "tokens=1,* delims=:" %%d in (
'echo("%%~c"^|findstr /ric:"REM %~2 end"'
) do (
if "!MarkerEnd!" equ "" set "MarkerEnd=%%b"
)
)
for /f "tokens=1,* delims=:" %%b in (
'findstr /rbinc:".*" "%~f1"'
) do (
set LineText=%%c
for %%l in (!filterScript.Labels!) do (
if "%%~c" equ "%%~l" set LineText=:%%c
)
if %%~b geq !MarkerStart! (
if %%~b leq !MarkerEnd! (
REM Skip line !LineText! @%%b
) else (
if "%~3" neq "" (
>>"%~f3" echo(!LineText!
) else (
>>"%~f1" echo(!LineText!
)
)
) else (
if "%~3" neq "" (
>>"%~f3" echo(!LineText!
) else (
>>"%~f1" echo(!LineText!
)
)
)
endlocal
exit /b
:labelList Script [Rtn]
setlocal EnableDelayedExpansion
set "labelList.File=%~1"
if not exist "!labelList.File!" set "labelList.File=%~f0"
set "labelList.Rgx= *"
set "labelList.Rgx= *<*:@*[-a-z0-9_.\\\[\]/]*[-a-z0-9_.\\\[\]/#$]"
set "labelList.Rgx=!labelList.Rgx![-a-z0-9_.]*"
for /f "tokens=* delims=:" %%b in (
'findstr /rbic:"!labelList.Rgx!" "!labelList.File!"'
) do (
if "%~2" neq "" (
if "%~2" neq " " (
for /f "tokens=1" %%u in ("%%~b") do (
set "labelList.Rtn=!labelList.Rtn:<:=!%%u "
)
) else echo(%%b
) else echo(%%b
)
if "!labelList.Rtn!" neq "" (
set "labelList.Rtn=!labelList.Rtn:~0,-1!"
for /f "usebackq tokens=1,* delims==" %%b in (
`set labelList.Rtn`) do (endlocal
set "%~2=%%~c"
)
) else endlocal
exit /b
Results/output:
Code: Select all
@echo off
echo Type 1 for Super Mario 64, type 2 for Ocarina of Time, type 3 for Majora's Mask
set /p input=
if %input%==1 goto Game1
if %input%==2 goto Game2
if %input%==3 goto Game3
REM Game1 start
:Game1
cd "C:\Users\Giovanni\Desktop\Emuladores\Nintendo 64\---"
start Project64.exe "C:\Users\Giovanni\Desktop\Emuladores\Nintendo 64\Roms\Super Mario 64 (USA).z64"
exit
REM Game1 end
REM Game2 start
:Game2
cd "C:\Users\Giovanni\Desktop\Emuladores\Nintendo 64\---"
start Project64.exe "C:\Users\Giovanni\Desktop\Emuladores\Nintendo 64\Roms\Legend of Zelda, The - Ocarina of Time (USA).n64"
exit
REM Game2 end
Edit: it seems I forgot about the part that says 'if %input%==3 goto Game3'
But perhaps you can resolve that easily.
You can use the same tactic with the code I've provided.
Just place some start and end markers in a REM statement surrounding the parts you want to filter out and call filterScript with marker specified.
If the scripts you want to filter are automatically generated with other code, you can also adjust that other code to add these REM and call filterScript statements.