Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


Simple script for copying a file while removing some text in the file

 
Logged in as: Guest
arrSession:exec spGetSession 2,2,54337
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Simple script for copying a file while removing some text in the file
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1]
Login
Message << Older Topic   Newer Topic >>
 Simple script for copying a file while removing some te... - 12/14/2007 8:56:50 AM   
  bhathaway

 

Posts: 2
Score: 0
Joined: 12/14/2007
Status: offline
Hi - I am a complete novice to scripting.  Was wondering if someone could help me create a script that will simply copy a text file from one place to another while at the same time deleting a word that is in the file.  For instance if I have the following in a text file:


text line 1
text line 2 blah blah blah
text line 2 with "password=password"
text line 4 blah blah

I want to copy the text file to another location so that it removes or replaces the password such as:


text line 1
text line 2 blah blah blah
text line 2 with "password=XXXXX"
text line 4 blah blah

Thanks for any help that can be given.
 
 
Post #: 1
 
 RE: Simple script for copying a file while removing som... - 12/14/2007 9:03:54 AM   
  dm_4ever


Posts: 2663
Score: 46
Joined: 6/29/2006
From: Orange County, California
Status: offline
Do a search of FileSystemObject and OpenTextFile method and MoveFile method...and you also want to take a look at the Replace Function.

_____________________________

dm_4ever

My philosophy: K.I.S.S - Keep It Simple Stupid
Read Me: http://www.visualbasicscript.com/m_24727/tm.htm
Frequently Asked Stuff: http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to bhathaway)
 
 
Post #: 2
 
 RE: Simple script for copying a file while removing som... - 12/14/2007 9:54:10 AM   
  ehvbs

 

Posts: 2200
Score: 50
Joined: 6/22/2005
From: Germany
Status: offline
Hi bhathaway,

have a look at this:


      

output:


      

As dm_4ever proposed, I use a FileSystemObject and OpenTextFile to read the text. To modify
the text a RegExp is more convenient than a simple string Replace. No need to move the file - just
create and write to a new file.

Good luck!

ehvbs

(in reply to dm_4ever)
 
 
Post #: 3
 
 RE: Simple script for copying a file while removing som... - 12/14/2007 10:36:47 AM   
  bhathaway

 

Posts: 2
Score: 0
Joined: 12/14/2007
Status: offline
Fantastic...works perfectly. thanks for your help!

(in reply to ehvbs)
 
 
Post #: 4
 
 RE: Simple script for copying a file while removing som... - 3/5/2008 1:56:57 AM   
  Birdy

 

Posts: 5
Score: 0
Joined: 3/4/2008
Status: offline
hello can you maybe also help me a little with the same code?
i want the same but without the "" brackets
so that everything after (password=) will be replaced with xxxxx

thanks

(in reply to ehvbs)
 
 
Post #: 5
 
 RE: Simple script for copying a file while removing som... - 3/5/2008 2:05:40 AM   
  ebgreen


Posts: 5036
Score: 31
Joined: 7/12/2005
Status: online
So use what ehvbs pointed but without the "s.

_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to Birdy)
 
 
Post #: 6
 
 RE: Simple script for copying a file while removing som... - 3/5/2008 3:04:19 AM   
  ehvbs

 

Posts: 2200
Score: 50
Joined: 6/22/2005
From: Germany
Status: offline
Hi Birdy,

changes:

Dim oRE     : Set oRE = New RegExp
  oRE.Pattern   = "(password=).*?\r$"
oRE.Multiline = True
  oRE.Global    = True

WScript.Echo sText
  sText = oRE.Replace( sText, "$1XXXXX" & vbCr )
  WScript.Echo "------- After -------"

Good luck!

ehvbs

(in reply to ebgreen)
 
 
Post #: 7
 
 
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Simple script for copying a file while removing some text in the file Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts