Adding information to a config file and smart counting

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
ns1207
Posts: 2
Joined: 13 Dec 2009 03:26

Adding information to a config file and smart counting

#1 Post by ns1207 » 13 Dec 2009 03:37

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.

!k
Expert
Posts: 378
Joined: 17 Oct 2009 08:30
Location: Russia

#2 Post by !k » 13 Dec 2009 06:30

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

ns1207
Posts: 2
Joined: 13 Dec 2009 03:26

#3 Post by ns1207 » 13 Dec 2009 09:45

Thanx, Works perfectly.

Post Reply