Solved Batch text settings file

April 10, 2013 at 10:20:38
Specs: Windows 7, Intel(R) Core(TM) i3 / 3.20 GHz / 8 GB Ram
Hi, I need some help with batch.

I want a code that reads a txt file and looks for something like this: lamp=1

And if it finds it, it will assign a variable like this(ex. from above): set lamp=1

Any help would be apreciated.

Sorry if my English is a bit bad.


See More: Batch text settings file

Report •


✔ Best Answer
April 12, 2013 at 18:09:27
@echo off & setlocal
for /f "tokens=*" %%a in ('findstr /r /c:"^[^:]..*=..*$" tempfile') do set %%a
:: show the results
set
pause
::==== end

Note that if there is an = in the middle of other text, it will still be assigned as well, like:
one two three=four five six
will assign "four five six" to a var called "one two three", so I'm dubious of whether the beg-of-line/end-of-line even matter.
If you want the variables to be global, remove the setlocal in line 1.



#1
April 10, 2013 at 12:40:59
Your English is OK.

Post a few lines of the file.

=====================
M2 Golden-Triangle


Report •

#2
April 10, 2013 at 12:41:55
findstr is the command you'll probably want to use.

example: findstr /m "%searchterm%" "%txtfile%"


Report •

#3
April 10, 2013 at 17:58:28
If it's on a line by itself, it would be pretty easy. If it's embedded within a line, it will need more attention, so a sample of the target-file would be most helpful.

Report •

Related Solutions

#4
April 11, 2013 at 10:17:27
@echo off
:: You could just press ctrl + f to search for a string.
color 9f
mode 56,7
Title Search For a string
echo.Please enter the file name (or type desktop:filehere):
echo.
set /p file=File name:
if %file:~0,8%==desktop: set file=C:\Users\%username%\desktop\%file:~8%
cls
echo.Type in the string you want to search:
echo.
set /p text=Text String:
mode 150,70
findstr /i /c:"%text%" %file%
:: To write the output into a text file un comment the next line and comment the
:: previous line:
:: findstr /i /c:"%text%" %file% >> C:\Users\%username%\Desktop\Temp.txt
pause > nul
exit

Report •

#5
April 12, 2013 at 00:13:17
Eh, kinda did not understand anything. But here's a few lines of the text file:
---
path=
::Tells the manager where to place the mods.

modpath=
::Tells the manager where the mods are placed.
---

And i want to seperate out the ones without :: and be able to set a variable up for each
'something=text'
So that would execute this: set something=text


Report •

#6
April 12, 2013 at 18:09:27
✔ Best Answer
@echo off & setlocal
for /f "tokens=*" %%a in ('findstr /r /c:"^[^:]..*=..*$" tempfile') do set %%a
:: show the results
set
pause
::==== end

Note that if there is an = in the middle of other text, it will still be assigned as well, like:
one two three=four five six
will assign "four five six" to a var called "one two three", so I'm dubious of whether the beg-of-line/end-of-line even matter.
If you want the variables to be global, remove the setlocal in line 1.


Report •

#7
April 16, 2013 at 01:17:58
Thanks :) I can't wait to make the mod mannager done!

Report •


Ask Question