/build/static/layout/Breadcrumb_cap_w.png

Append or Add lines in a ini file

Hi out there.

I want to append or add somelines to a ini file.

Example. I have a notes.ini file, at c:\notes\data\notes.ini
and i want to add or append some new lines to the existing Ini file.

Line 1 = XXXXX
Line 2 = KKKKK
Line 3 = PPPPPP

I have a another ini file or a text file, where above line have to added/append to the Notes.ini

Can anyone tell me a script to do it.

0 Comments   [ + ] Show comments

Answers (6)

Posted by: captain_planet 15 years ago
Black Belt
0
If you're trying to accomplish this from a Windows Installer you should be using the IniFile table. However, if you do require a script just use the file system object. The following code will append three lines to the end of the ini file:



Const ForAppending = 8
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("C:\notes.ini", ForAppending)
objFile.WriteLine "XXXXX"
objFile.WriteLine "KKKKK"
objFile.WriteLine "PPPPPP"
objFile.Close

Posted by: SKS 15 years ago
Orange Belt
0
Thnx mate, ur script works and append in the end of the file. [:D]

I was working on this script, and everytime i launch it it erase what i had in the Notes.ini file, and added the
text i wanted, so the problem was that i cant append the text in the end of a file.

If you can tell what had to be modify in my script. " just for learning and understand it" [&:]

Option Explicit
Dim objFSO, objFileCopy, objAddText
Dim strFilePath
Dim strFileText1, strFileText2, strFileText3
strFilePath = "C:\Notes\Data\Notes.ini"
strFileText1 = "XXXXXXX"
strFileText2 = "VVVVVVV"
strFileText3 = "NNNNNNN"
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objAddText = objFSO.CreateTextFile(strFilePath, True)

objAddText.WriteLine (strFileText1)
objAddText.WriteLine (strFileText2)
objAddText.WriteLine (strFileText3)
objAddText.Close
Posted by: anonymous_9363 15 years ago
Red Belt
0
ORIGINAL: SKS
I was working on this script, and everytime i launch it it erase what i had in the Notes.ini file, and added the
text i wanted, so the problem was that i cant append the text in the end of a file.
Your problem is that you're using the CreateTextFile method, rather than OpenTextFile. So your code needs changing to test for the file's existence and, if found, use OpenTextFile and if not, use CreateTextFile. See here http://www.devguru.com/technologies/vbscript/14048.asp for a reasonable reference to FileSystemObject (and VBScript in general).

Anyway, I think this is completely the wrong approach and fraught with potential for error. As Captain Planet said, if you're doing this in an MSI, use the INIFile table. If not, Google for 'clsINI' (or does my memory serve me that it can be found at http://www.jsware.net as part of a toolkit?) which is a rather nice INI class file which you can append to your script file. Don't be put off by the dreaded word 'class' - it's a snap to use.
Posted by: SKS 15 years ago
Orange Belt
0
Thnx for the info and the explanation Vbscab :-)
Posted by: SKS 15 years ago
Orange Belt
0
Nice script from captain_planet which works.
But if i want to make a check on a line exist ( "XXXXX" ), and if so, then quit the script, otherwise install the script.
Can you help me on that. Thnx.

Const ForAppending = 8
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("C:\notes.ini", ForAppending)
objFile.WriteLine "XXXXX"
objFile.WriteLine "KKKKK"
objFile.WriteLine "PPPPPP"
objFile.Close
Posted by: anonymous_9363 15 years ago
Red Belt
0
Look up 'ReadLine' (or 'ReadAll'if you prefer) on DevGuru. http://www.devguru.com/technologies/vbscript/14126.asp
Rating comments in this legacy AppDeploy message board thread won't reorder them,
so that the conversation will remain readable.
 
This website uses cookies. By continuing to use this site and/or clicking the "Accept" button you are providing consent Quest Software and its affiliates do NOT sell the Personal Data you provide to us either when you register on our websites or when you do business with us. For more information about our Privacy Policy and our data protection efforts, please visit GDPR-HQ