0

Say I include a .zip file with some files, namely my batch script (Which is 90% complete) and a .ini with the name "game-WINDOWSNAME.ini" and inside said ini are a couple lines

vid_defheight=y
vid_defwidth=x

And I want my batch script to be so upon running it, it asks for "screen res x" for "vid_defwidth=x" and screen res y for "vid_defheight=y" and the user inputs a value for each one, say for example "1920 and 1080" and then the .ini changes said lines to match e.g.

vid_defheight=1080
vid_defwidth=1920

How do I do this?


[Edit : add-in code-in-use]

So I made this based on more googling, but all it does is read the file into the console. Could someone tell me what I'm doing wrong?

@echo off &setlocal
set "search=oldcrapx"
set "replace=1920"
set "textfile=zdoom-WINDOWSNAME.ini"
set "newfile=zdoom-%username%.ini"
(for /f "delims=" %%i in (%textfile%) do (
    set "line=%%i"
    setlocal enabledelayedexpansion
    set "line=!line:%search%=%replace%!"
    echo(!line!
    endlocal
))
pause
Magoo
  • 77,302
  • 8
  • 62
  • 84
  • How do you do which? Ask a user to input values? Write those values to an `.ini` file? Get the current user's username? Rename a file? Have you Googled any of this, or are you just looking for someone to write your script for you? – rojo Jan 06 '15 at 01:26
  • I've done googling, couldn't find what I'm looking for. I found out how to rename, so ignore that. I mainly want to know how to ask for user input for screen resolution x and y, and have it REPLACE the x and y values for vid_defwidth=x and vid_defheight=y with the user input values. – Loismustdie555 Jan 06 '15 at 01:31

2 Answers2

0

Alter

))

to

))>"%newfile%"

and you'll get that output placed in the new file "zdoom-%username%.ini" (where %username% will have been replaced by a sack of potatoes.)

Magoo
  • 77,302
  • 8
  • 62
  • 84
0

Would you rather ask the user to input the resolution, or get the desktop resolution from WMI? You can get the desktop resolution automatically without prompting the user for it like this:

@echo off
setlocal

:: make sure vars are undefined
set ScreenWidth=
set ScreenHeight=

for /f "delims=" %%I in ('wmic desktopmonitor get ScreenWidth^,ScreenHeight /format:list ^| find "="') do (
    set "%%I"
    if defined ScreenWidth if defined ScreenHeight goto next
)

:next
echo Display is %ScreenWidth% x %ScreenHeight%
:: record %ScreenWidth% and %ScreenHeight% to ini file

If you'd rather ask the user to input the width and height values, use set /P. See help set in a cmd console for more information. Here's an example:

set /P "vid_defwidth=Screen res X: "
set /P "vid_defheight=Screen res Y: "
echo You defined a resolution of %vid_defwidth% x %vid_defheight%

In the previous example, the script echoes Screen res X: to the console with the cursor at the end, waiting for user input. When the user inputs some text, the script sets %vid_defwidth% to that text and moves to the next line to ask for Screen res Y:.


Since you're new at batch scripting and programmatically editing an INI file might be a bit advanced for your level of experience, you might consider using an external helper to modify your INI file. See the second half of this answer (scroll down to the Update section) for a good choice (if I do say so, myself).

Community
  • 1
  • 1
rojo
  • 24,000
  • 5
  • 55
  • 101