Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Name: pball
I'm working on a script (same one that's been in my last 4-5 posts) and I want to read some settings from a separate txt file. I'm surprised I was easily able to make the script work except for one part. I'm guessing there is some trick or something to get this to work.
@echo off
setlocal EnableDelayedExpansionset num=1
for /f "tokens=*" %%a in (settings.txt) do (
set !num!=%%a
)
pauseThe first line in the loop doesn't set the value of !num! to the value of %%a. I'm guessing you can't have a variable set to another variable.
How can I have an incrementing number set equal to the contents of the line that is being read.
So when the script is done, each line in the settings file would be a variable that is the line number it comes from in the file.
edit
found a simpler wayfor /f "tokens=*" %%a in (settings.txt) do (
set %%a
)with the setting file set up like this
hey=c:\watever\hey.exe
works, is simple, makes the script smaller. I love getting scripts as small and efficient as possible.

It is possible to set the string inside a variable to another value eg set %var%=whatever. You, however, can not use variables that start with numbers in a batch file(it can be done on the command line). For example the variable %a9% is valid but the variable %9a% is not. This is because they conflict with command line agruments eg %0, which of course is the name of the batch file.

Thanks I did not know that. I'm glad I still posted this cause I learned something very good to know.

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |