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.
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)
Please log in to answer
Posted by:
captain_planet
16 years ago
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
16 years ago
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
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
16 years ago
ORIGINAL: SKSYour 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).
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.
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
16 years ago
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
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
16 years ago
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.
so that the conversation will remain readable.