[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 639
  • Last Modified:

Script to Replace Text in a file

Need a little help. I have a vbscript that will open up a file extension and change "Program Files" text to "Program Files (x86)". The problem is that if "Program Files (x86)" already exist in the file the script is apending and changing to  "Program Files (x86) (x86)". Trying to find a way to have the script look for "Program Files (x86)" and if exist do nothing, but continue to change "Program Files" to "Program Files (x86)". Here is the script:


Thanks
Test.vbs
0
jspade_69
Asked:
jspade_69
  • 2
1 Solution
 
als315Commented:
Can you show your text file?
May be there is something like Program Files\ and Program Files (x86)\?
0
 
fiboCommented:
1 - What happens if you change

   strNewText = Replace(strText, "Program Files", "Program Files (x86)")

to
   strNewText = Replace(strText, "Program Files\", "Program Files (x86)\")

2 - If this is a quick and dirty one shot, consider to replace
   strNewText = Replace(strText, "Program Files", "Program Files (x86)")
by
   strNewText = Replace(strText, "Program Files", "Program Files (x86)")
   strNewText = Replace(strText, "Program Files (x86)  (x86)", "Program Files (x86)")
0
 
jspade_69Author Commented:
Thanks fibo...you're 1st suggestion worked like a champ....so simple yet so affective!   By the way i originally tried the 2nd option before posting and it didn't work.

Thanks again
0
 
fiboCommented:
B-) Glad it worked and I could help. Thx for the grade and points!
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now