Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


Replace function in VBSript

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

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Replace function in VBSript
  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 >>
 Replace function in VBSript - 12/13/2006 4:21:53 AM   
  caryma77

 

Posts: 27
Score: 0
Joined: 9/19/2006
Status: offline
I am trying to use a replace function but keeps getting an error file exist.

Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.GetFolder(FolderDir)
Set fc = f.Files

For Each f1 in fc
f1.Name = Replace(f1.Name,".GZ","")

Next
 
 
Post #: 1
 
 RE: Replace function in VBSript - 12/13/2006 5:07:08 AM   
  ginolard


Posts: 1082
Score: 21
Joined: 8/10/2005
Status: offline
Replace is for replacing strings not for renaming files. 

_____________________________

Author of ManagePC - http://managepc.net
AD Query Template - http://www.visualbasicscript.com/m_40609/tm.htm
Consolidated Scripting Framework - http://www.visualbasicscript.com/m_59109/tm.htm

(in reply to caryma77)
 
 
Post #: 2
 
 RE: Replace function in VBSript - 12/13/2006 5:43:41 AM   
  ehvbs

 

Posts: 2220
Score: 50
Joined: 6/22/2005
From: Germany
Status: offline
Hi carym77,

this output:


      

and this code:


      

show that

  (a) your technique to rename a file is sound in principle

  (b) there must be a file with sNewName already in your folder

(in reply to ginolard)
 
 
Post #: 3
 
 
 
  

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 >> Replace function in VBSript 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