Page 1 of 1

Adding information to a config file and smart counting

Posted: 13 Dec 2009 03:37
by ns1207
Hi,

I am looking for a batch file that reads the last line of a configfile with the following info:

name001=pc12300
name002=pc10000
name003=pc14000

Now when the batch file is run from pc13033, the following line should be added to the last line of a config file:

name004=pc13033

%computername% already gives the computername of the pc.

Is this possible?
Anyone wants to help me out?

Thanx in advance.

Posted: 13 Dec 2009 06:30
by !k

Code: Select all

@echo off
set "config=c:\configfile.txt"

setlocal enableextensions enabledelayedexpansion
set next=0
for /f "usebackq tokens=1,* delims==name" %%a in ("%config%") do (
echo %%a = %%b
if "%computername%"=="%%b" exit /b
if !next! LSS %%a set next=%%a
)
for /f "tokens=* delims=0" %%n in ("%next%") do set "next=%%n"
set /a next=%next%+1
if %next% LSS  10 set next=0%next%
if %next% LSS 100 set next=0%next%
echo %computername% is %next%
echo name%next%=%computername%>>"%config%"

pause &exit /b

Posted: 13 Dec 2009 09:45
by ns1207
Thanx, Works perfectly.