Inserting Lines to an INI file

Chris February 3, 2009 at 15:38:48
Specs: Windows Vista
I found some very helpful articles on this site, but I'm having trouble with this one...

Here is the applicable batch code:

@echo off > %AppData%\PROGRAM\NEW.INI
setLocal EnableDelayedExpansion

if not errorlevel 1 goto :FOUND

for /f "tokens=1 delims=[] " %%a in ('find /n "[SERVERS]" ^< %AppData%\PROGRAM\EXISTING.INI') 

do (
set /a i=%%a

for /f "tokens=* delims= " %%a in (%AppData%\PROGRAM\EXISTING.INI) do (
set /a n+=1
echo %%a >> %AppData%\PROGRAM\NEW.INI
if !i! equ !n! echo DESIRED STRING >> %AppData%\PROGRAM\NEW.INI

 edit %AppData%\PROGRAM\NEW.INI
goto :EOF

goto :EOF


The EXISTING.INI file has blank lines in it that are not copied to a NEW.INI file, therefore when inserting new lines into the NEW.INI file they are inserted at the incorrect locations.

For example - A new string should be inserted at line 120 of the EXISTING.INI, however the NEW.INI is without the blank lines of the EXISTING.INI file and what was line 120 is now line 113 so the new string is inserted at the "new" line 120 ("old" line 127) of the NEW.INI file.

Does that make sense? Any idea how I can make this batch copy the blank lines to the NEW.INI file?

Thanks in advance!

See More: Inserting Lines to an INI file

Report •

February 3, 2009 at 16:17:59
Maybe you can try
this free application.It let you:

Manipulate with an INI-file and its elements by the easiest way from any programming language. The INI-File Manager ActiveX can be used from VB, VBA, VB.NET, VC++, VC.NET, VBScript,JScript,Delphi, ASP, ASP.NET and any other programming languages which support COM/ActiveX technology.

Available features are:

* Create new INI-file.

* Load existed INI-file from disc file.

* Update changes INI-file into disc file.

* Encrypt whole INI-file from ascii to binary.

* Decrypt whole INI-file from binary to ascii.

* Add/Search/Delete section of INI-file.

* Add/Search/Delete key in section.

* Encript/Decript a single key value.

Good,luck pb.

Report •

February 3, 2009 at 19:11:05
That's not going to work for me. I need to customize each user's INI file with a batch/logon script - I might find a use for that program somewhere else though...

Anyone else?

Report •

Report •

Related Solutions

February 4, 2009 at 12:19:41
Thanks for trying to help PB, but I already
know how to apply logon scripts and such.

What I don't know is this:
Given the current batch code, is there a way
to copy blank lines from EXISTING.INI to
NEW.INI -OR- is there a better way to do
what I'm wanting?

Report •

February 5, 2009 at 12:03:39
Here's how you get it to include blank lines.

@echo off > newfile & setLocal EnableDelayedExpansion

for /f "tokens=1-2* delims=[]" %%a in ('find /v /n "" ^< myfile') do (
if "%%b"=="" (
echo. >> newfile
) else (
echo %%b >> newfile

If at first you don't succeed, you're about average.


Report •

Ask Question