Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Changing text in text files. Help

Status
Not open for further replies.

mrclasik

Technical User
Dec 16, 2004
18
US
Hi, I want to start by saying I know nothing about VBScripts. With that said, I am trying to figure out a way to find and replace text in a text file. I am looking to do something like this....

:::c:baseURL="jar:file:///C:/Documents%20and%20Settings/clasik/Application%20Data/Mozilla/Firefox/Profiles/clasik/extensions/%7Be22068c8-faf8-4620-b0d6-e2811a82e84b%7D/chrome/needlesearch.jar!/locale/zh-CN/needlesearch/">
<c:package :::

I would like to change every instance of C:/Documents%and%Settings/clasik/Application%20Data/Mozilla/Firefox/profiles/clasik
to something else.

The instances of the word clasik needs to be a variable.

Is this posible to do.. I am working on a deployment method for firefox and this would be the final thing I need to make it work.

Any help would be appreciated..

Thanks,

Clasik
 
Something like this.
[tt]
'---
'your input here
filespec="d:\test\abc.txt"
sbase="C:/Documents%20and%20Settings/clasik/Application%20Data/Mozilla/Firefox/Profiles/"
sname="clasik"
ssomethingelse="xyz"
'---

set fso=createobject("scripting.filesystemobject")
set ots=fso.opentextfile(filespec,1,true)
s=ots.readall
ots.close
[green]'if the file content is not in escaped format, add this statement
's=escape(s)[/green]
s=replace(s,sbase&sname,ssomethingelse)
[green]'again if
's=unescape(s)[/green]
set ots=fso.opentextfile(filespec,1,true)
ots.write s
ots.close
set ots=nothing
set fso=nothing
[/tt]
 
Amendment:
The writing part (the second), the line should read:
[tt] set ots=fso.opentextfile(filespec,[red]2[/red],true)
[/tt]
 
thanks for the reply tsuji. Let me clarify a couple of things to see if this is going to work.. This whole line will need to be changed C:/Documents%20and%20Settings/clasik/Application%20Data/Mozilla/Firefox/Profiles/clasik

It would be changed to ****CHANGETHISSTRING****.

So in effect it would look like. c:baseURL="jar:file:///****CHANGETHISSTRING****/extensions/%7Be22068c8-faf8-4620-b0d6-e2811a82e84b%7D/chrome/needlesearch.jar!/locale/zh-CN/needlesearch/">
<c:package

The world Clasik I need to be a variable in the script for this pertains to the logged on user. The file that I am trying to modify is chrome.rdf out of the firefox app data\profile

There are many instances of that line I need to change. It points to locations of extensions and themes for firefox.

Is there a way to make the word clasik or any word in that same space varible in the script. so if say chuck was in its space it would still change the line to what it needs to be.

C:/Documents%20and%20Settings/clasik/Application%20Data/Mozilla/Firefox/Profiles/clasik
or
C:/Documents%20and%20Settings/chuckclasik/Application%20Data/Mozilla/Firefox/Profiles/chuckclasik
to
c:baseURL="jar:file:///****CHANGETHISSTRING****/extensions/%7Be22068c8-faf8-4620-b0d6-e2811a82e84b%7D/chrome/needlesearch.jar!/locale/zh-CN/needlesearch/">
<c:package

Thanks for the help...
 
I overlooked there is another clasik in the sbase. Here is the obvious relisting.
[tt]
'---
'your input here
filespec="d:\test\abc.txt"
sbase1="C:/Documents%20and%20Settings/"
sbase2="/Application%20Data/Mozilla/Firefox/Profiles/"
sname="clasik"
ssomethingelse="xyz"
'---

set fso=createobject("scripting.filesystemobject")
set ots=fso.opentextfile(filespec,1,true)
s=ots.readall
ots.close
'if the file content is not in escaped format, add this statement
's=escape(s)
s=replace(s,sbase1&sname&sbase2&sname,ssomethingelse)
'again if
's=unescape(s)
set ots=fso.opentextfile(filespec,2,true)
ots.write s
ots.close
set ots=nothing
set fso=nothing
[/tt]
 
Can a variable be used for clasik? If so , this would work perfectly..
 
It is in the variable sname already.
[tt] sname="clasik"[/tt]
Just make good use of it and feed it with some dynamically/statically obtained string.
 
I see. This will work.. I was hoping for a variable something like C:/Documents%20and%20Settings/*this could be anything*/Application%20Data/Mozilla/Firefox/Profiles/*this could be anything*

But this will do... Thanks for your help.. I tried it and it works great..

Is it posible to grab the users name and insert it into the sname=? That would be the move.. That would make this fully automated.. I am going to try to learn this scripting. Any good reads.?

Thanks again..

Clasik
 
Have a look at this:
MsgBox CreateObject("WScript.Network").UserName

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
that's cool PH. Now how do we get the username to = sname in that script.?
 
how do we get the username to = sname in that script?
You really have no idea how to do that ?
sname=CreateObject("WScript.Network").UserName

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
I told you have no clue of vbscript.. :)
But with you two helping, it worked.. it really worked...

 
You don't build the foundation of a 5-storey building from the 2nd floor. Read some basic material on the web and the manual from microsoft.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top