Computing.Net > Forums > Programming > adding text into specific location into .ini

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

adding text into specific location into .ini

Reply to Message Icon

Name: labib
Date: July 29, 2009 at 00:50:13 Pacific
OS: Windows XP
Product: Kingston 256mb module for dell poweredge 2300 333/350/400/450
Subcategory: General
Comment:

i need to add a specific line of text into a specific location after finiding the word [ORAGTWY] the below is the .ini file which i need to add the text into it:


; Settings for 25-User-SqlBase Server
[dbnt25sv]
country=germany
cache=2000
sortcache=2000
readonly=0
oracleouterjoin=0
logfileprealloc=0
partitions=0
optimizerlevel=2
locktimeout=275

[dbnt25sv.dll]
comdll=sqlws32
comdll=sqlapipe

[win32client]
country=germany
clientname=Win32User
SetZeroLengthStringsToNull=ON

[win32client.dll]
comdll=sqlws32
comdll=sqlora32
comdll=sqlodb32

[win32client.ws32]
serverpath=SRVxxx,<localhost>/WCxxx

[ORAGTWY]
REMOTEDBNAME=pos401a1,@pos401a1
REMOTEDBNAME=posprd2,@posprd2
REMOTEDBNAME=bscsprd2,@bscsprd2
REMOTEDBNAME=BSCSPRE7,@BSCSPRE7
REMOTEDBNAME=BSCSPRE7,@BSCSPRE7
REMOTEDBNAME=SIEBPRD2,@SIEBPRD2


servername=server1
REMOTEDBNAME=WCDB,@WCDB

[ODBCRTR]

[SQLTALK]
country=germany

[SQLAPIW]
country=germany



Sponsored Link
Ads by Google

Response Number 1
Name: labib
Date: July 29, 2009 at 02:15:50 Pacific
Reply:

plz i need any response


0

Response Number 2
Name: Mechanix2Go
Date: July 29, 2009 at 04:34:35 Pacific
Reply:


@echo off > newfile & setLocal enableDELAYedexpansion

for /f "tokens=* delims= " %%a in (my.ini) do (
echo %%a >> newfile
if %%a equ [ORAGTWY] (
echo my text >> newfile
)
)


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

M2


0

Response Number 3
Name: labib
Date: July 29, 2009 at 04:46:35 Pacific
Reply:

Dear Mechanix2Go,
Thanks for the reply but what you replied with was a script to create a new file "newfile" and copy all the contents of the old file into it and insert the text i want if i find the specific word, which is perfect except that i only want to INSERT in the old file (i.e; edit the old file rather than create the new file)..is that possible?
Thanks alot anyways.


0

Response Number 4
Name: labib
Date: July 29, 2009 at 05:24:41 Pacific
Reply:

Dear Mechanix

plz i need your help as fast as you can i have a change tonight on 300 machine :D

Thanks for your support


0

Response Number 5
Name: Mechanix2Go
Date: July 29, 2009 at 05:40:37 Pacific
Reply:

It's usually not a good idea to modify a file which is open for reading.


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

M2


0

Related Posts

See More



Response Number 6
Name: labib
Date: July 29, 2009 at 06:05:27 Pacific
Reply:

no it's not open cause it will be done after working hours


0

Response Number 7
Name: labib
Date: July 29, 2009 at 06:50:24 Pacific
Reply:

is there any solution plz i need your help


0

Response Number 8
Name: Mechanix2Go
Date: July 29, 2009 at 07:18:45 Pacific
Reply:

I don't know of a way to read & write at the same time. What's wrong with creating a new file?


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

M2


0

Response Number 9
Name: ghostdog
Date: July 29, 2009 at 18:30:03 Pacific
Reply:

@labib, it is YOUR job to try and do this yourself in the first place. therefore, as much as M2 wants to help you, do not exploit his kindness by "rushing" him to do YOUR job.

that said, with batch or vbscript(AFAIK), there is no mechanism to edit a file in place. If you want, download sed for windows which provides you this capability.

GNU win32 packages | Gawk


0

Response Number 10
Name: gtaion
Date: August 19, 2009 at 13:07:35 Pacific
Reply:

Ghost I hate to get into the middle of pissing matches, but technically you are correct that you can't read and write the file at the same time, but that's not saying that you can't use VBScript to read the file into memory, then write from memory to the existing file with the added lines. Even though I am pretty new to writing scripts you can do something like the following to complete the task without having to create a new file.

strNewLine = "New Line to Write"
strFileName = "c:\test.ini"
strCheckForString = UCase("[ORAGTWY]")

Set objFS = CreateObject("Scripting.FileSystemObject")
StrContents = Split(objFS.OpenTextFile(strFileName).ReadAll, vbNewLine)
Set objTS = objFS.OpenTextFile(strFileName, 2)
For Each strLine In StrContents
If (Left(UCase(LTrim(strLine)),Len(strCheckForString)) = strCheckForString) Then
objTS.WriteLine strLine: objTS.WriteLine strNewLine
else
objTS.WriteLine strLine
End If
Next
Wscript.quit


0

Response Number 11
Name: lucas999
Date: August 21, 2009 at 04:56:06 Pacific
Reply:

Simply use C and Win32 INI apis
See on Win32 ng
http://tinyurl.com/cmhb5g
for C code.


0

Sponsored Link
Ads by Google
Reply to Message Icon






Post Locked

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


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: adding text into specific location into .ini

echo text to specific line in file www.computing.net/answers/programming/echo-text-to-specific-line-in-file/11965.html

Batch file adding text to file also www.computing.net/answers/programming/batch-file-adding-text-to-file-also/16756.html

Parsing similar lines from text www.computing.net/answers/programming/parsing-similar-lines-from-text/16639.html