I have several configuration files (over 40) and I need to replace multiple categories with the updated categories.  I have a csv file with one column containing the old categories and another column containing the new categories.


Ideally, I would like for the script to reference the csv file and be able to automatically run through all config files.


I have a very basic script that will replace one word with another word, but I have not been able to expand it beyond that.


This is the script I have;


 Const ForReading = 1
Const ForWriting = 2

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("C:\Scripts\Text.txt", ForReading)

strText = objFile.ReadAll
strNewText = Replace(strText, "Old", "New")
strNewText1 = Replace(strNewText, "Day", "Night")
strNewText2 = Replace(strNewText1, "1", "2")

Set objFile = objFSO.OpenTextFile("C:\Scripts\Text.txt", ForWriting)
objFile.WriteLine strNewText2

Answer Summary:
2 Comments   [ - ] Hide Comments


  • You might want to consider using Perl.
    In the end you read in the categories and loop through each. You read in the file you want to modify just before the loop. You replace text inside the loop using the values you read in from the categories file. After the loop you save the file.
    • yikes, i know even less about Perl than I do about vbs
  • Your request is for something which - done properly - is a little complex. Consequently, you'll struggle to get anyone to spend any time building such a thing for you.

    As a pointer, I would suggest you read the CSV into an array and then loop through that array, passing the data into a function which does the replacement.
Please log in to comment

Answer this question or Comment on this question for clarity



This is build-in functionality  with RayPack or  Installshield.

Answered 05/07/2014 by: jaybee96
Red Belt

  • Show us where in InstallShield there is native handling for reading a CSV!
    • http://helpnet.installshield.com/installshield16helplib/TextFileChanges-CreateRef.htm
    • it works like a charm!
    • can you let me know if this works for you?
      I can send you an example MSI ?
      • You've mis-read the brief (not that it's crystal clear, admittedly.)

        The OP wants to read the changes from a CSV and then apply them to OTHER FILES.
Please log in to comment

I use this function to replase a string in a file: 

 Function ReplaceInFile(strFilePath, strToReplace, strNewValue)	Dim objFSO, objFile, strText, re	Set objFSO = CreateObject("Scripting.FileSystemObject")	if objFSO.FileExists(strFilePath) Then		Set objFile = objFSO.OpenTextFile(strFilePath, ForReading, True)			strText = objFile.ReadAll		objFile.Close		Set objFile = Nothing				strText = Replace(strText, strToReplace, strNewValue, 1, -1, 1)			Set objFile = objFSO.CreateTextFile(strFilePath, True)		objFile.Write strText		objFile.Close		Set objFile = Nothing		End If	Set objFSO = NothingEnd Function


If you need help to use it, please tell me.


Answered 05/08/2014 by: terebent
Second Degree Brown Belt

  • thank you! i will try this out, it requires less scripting than the one i was using
Please log in to comment

you can replace entire strings of text also just by putting it in between quotes.  No idea on how to read a csv line by line to get the search and replace varibles

strNewText = Replace(strText, "Old string of text. to be replaced", "Is this the New text ?")

in this answer I replaced a string with another


strNewText = Replace(strText, "Old", "New")
Answered 05/06/2014 by: SMal.tmcc
Red Belt

  • the reason i would like to use a csv file is because i have over 100 categories i need to change, so the script i have will work, i would just need to add more conditions for each category change, i was trying to avoid that, but i may have to end up doing that after all :/
Please log in to comment