1.

Solve : editing .ini files?

Answer»

hey,

I'm trying to write a batch file that edit's a .ini files and copys it, and lots of other files from one pc to many.

I'm ok with the copying bit. (nice and easy ) but it's the editing line 15 of 150 with a ip address in a .ini file that i'm stuck on.

I suppose i could write the whole thing out and output it to a file but how could the >>c:\filename.ini be EXPANDED over 150 lines???

any ideas??you could use batch arithmetic (set /a) to increment a pointer as you read through a file line by line but the utility SED is tailor made for that kind of thing.
i'll explain a bit more...


I'm installing files in many sites, each site has between 2 and 10 Pc's.

The files in question are 3 that i have from a pre-made folder on the c:, but the last one is more tricky.

You can make and edit .ini files from batch. (but you have to type out the whole .ini file within the batch file).

I need to be able to make two changes to it, the ip address (changes from site to site but stays the same on machines at the same site) and the node number which has to change for every different machine it on.


short of having a choice "how many PC's do you have on this site" and lots of goto's for options 1 to 10, then typing out every ini file that it could need, is there a way to make some king of loop that can make (for example) make 4 .ini's with the same ip address in them but different machine numbers??


I can do this the long way round, which i night have to do as i need it by Wednesday, but if you can help that would be great.

you mention the set /a to increment a pointer, could you explain a bit further???

cheers guys

EDIT; i can't use any third party app's due to a corporate environment.

@echo off
set /a pointer=0
echo %pointer%

REM pointer is incremented by 1
set /a pointer += 1
echo %pointer%


COOL, cheers.



with ur help i can make as many files as i need with the CORRECT information. But i need to only do, say 4 loops and then stop. is there a way of counting how many you done and then stop at a pre defined number.

somthing like

set /a number=1
:loop
and echo.node = %number% >>file%number%.ini
set /a number +=1
if number=4 (goto end) else goto loop
:end
exit

You got the idea.

set /a number=1
:loop

REM not sure what you are trying to do here?
echo node = %number% >>file%number%.ini


set /a number +=1
if "%number%" EQ "4" goto end
goto loop
:end
exit
hey that sweet,

I suppose now i need to set a value to "count" depending on how many times i need it do it. something like


:2loops needed
set /a count=2
goto loop

:3loops needed
set /a count=3
goto loop

:loop
rem doing stuff!!!
set /a pointer +=1
if /i %pointer% NEQ %Count% goto loop
goto end


but i can't set that "count" amount.

any ideas?Quote from: blastman on October 01, 2007, 02:28:29 AM

:2loops needed
set /a count=2

:3loops needed
set /a count=3


if /i %pointer% NEQ %Count% goto loop

but i can't set that "count" amount.

any ideas?

Generally, NT command language is case-insensitive, but variables are not, so "Count" is treated differently from "count".yeah i noticed that just now, it seem to work now.

I have set the count an extra diget higher that then loops needed as the if line reloops if Not Equal to.

nice.

cheers.

now i have to use the ip address i've set ealier and strat using net use \\%ip%.13 and then copy the files i need after.

i'm getting there.......The other way you can do loops with a counter is to use FOR /L

FOR /L %%N IN (START,step,end) DO command

So this

FOR /L %%N IN (1,1,10) DO (
echo %%N
)

is equivalent to e.g. this BASIC code

FOR N=1 TO 10 STEP 1
PRINT N
NEXT N


And of course you can do this

set start=1
set step=1
set limit=10
FOR /L %%N IN (%start%,%step%,%limit%) DO (
echo %%N
)
ok, so i've written my batch file to make x amounts of ini files with node and ip numbers.

I 've also writen a loop that will copy the files to different machines (last octet counting with loop) but i now have the problem that one of the loops doesn't execpt the number 10 as a string. It seems to get 1 instead.

it might be easier if i email you my batch files (i would post it here but it quite long)

cheers dude!
Quote from: blastman on October 01, 2007, 09:13:54 AM
i now have the problem that one of the loops doesn't execpt the number 10 as a string. It seems to get 1 instead

You could post the relevant bit of code on here then it would help others too


Discussion

No Comment Found