0

So i've been looking at articles to see how to get this to work but everything has been going over my head. I'm trying to create a bat file that finds a game commandline.txt and changes a certain commandline for example a resolution

-width=1280 -height=720

to

-width=800 -height=400

for exmaple

and for it to save as the same .txt

I have written this for an example of code i want to use in a similar fashion and for you to get an idea of what i'm doing

@echo off
:MENU
CLS
echo+
echo 1 - game1
echo 2 - game2
echo+
echo+
SET /P MainMenuInput=Enter an option and press ENTER:
if %MainMenuInput% == 1 (
findstr "" "X:\game1\commandline.txt"
echo.%str%
set str=%str:-width=1280 -height=720=-width=800 -height=400%
echo.%str%
)
GOTO :MENU
if %MainMenuInput% == 2 (
findstr "" "X:\game2\commandline.txt"
echo.%str%
set str=%str:-width=1280 -height=720=-width=800 -height=400%
echo.%str%
)
GOTO :MENU

basically i have 2 games - i select number 1 which is game 1 and then it should change the width and height

So if i change it to this, it still doesn't work

@echo off
:MENU
CLS
echo+
echo 1 - Dev_NG
echo 2 - Dev_NG-Live
echo+
echo+
SET /P MainMenuInput=Enter an option and press ENTER:
if %MainMenuInput% == 1 (
set "search=-width=1280"
set "replace=-width=800"
set "textFile=%SettingFile%.txt"
for /f "delims=" %%i in ('type "%X:\game1\commandline.txt%" ^& break ^> "%X:\game1\commandline.txt%" ') do (
set "line=%%i"
setlocal enabledelayedexpansion
set "line=!line:%search%=%replace%!"
>>"%textFile%" echo(!line!
endlocal)
Barley
  • 1
  • 2
  • 1
    have you checked this http://stackoverflow.com/questions/60034/how-can-you-find-and-replace-text-in-a-file-using-the-windows-command-line-envir ? – npocmaka Feb 23 '17 at 20:17
  • Hey yeah, and i get confused :( i don't understand how to find the file i want to change the commandlines in – Barley Feb 23 '17 at 20:20
  • 1
    Possible duplicate of [Batch file : how to search and replace a string that have an "=" inside](http://stackoverflow.com/questions/37724410/batch-file-how-to-search-and-replace-a-string-that-have-an-inside) – aschipfl Feb 23 '17 at 22:45
  • It may be but i'd like someone to explain to me and help me as i dont understand that still, 1. where do i put X:\game1\commandline.txt ? to find the file and then where do i add the text to replace etc – Barley Feb 23 '17 at 23:43
  • anyone got any solutioons? – Barley Feb 24 '17 at 20:36

0 Answers0