?
Solved

Vbscript to go through files

Posted on 2011-09-23
4
Medium Priority
?
330 Views
Last Modified: 2012-06-21
Need a vb script that will go through files names in a directory and find "&" and replace it with "and"
0
Comment
Question by:chasmant
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 6

Expert Comment

by:effes
ID: 36589166
Have a look at the script on this page:
http://coderstalk.blogspot.com/2007/09/vbscript-to-replace-underscores-in.html

You will just have to tweak it a bit to do what you want. Like this:
' check if the file name contains underscore
If InStr(1, fil.Name, "&") <> 0 Then    '<-- replaced with ampersand
    ' replace underscore with space
    sName = Replace(fil.Name, "&", "and")    '<-- replaced with ampersand and "and"

Open in new window

Hope that helps.
0
 
LVL 1

Author Comment

by:chasmant
ID: 36589187
sorry I meant folder names not file names
so I would give it a path and then have it look through all sub directories and find "&" and remplace it with "and"
0
 
LVL 6

Accepted Solution

by:
effes earned 2000 total points
ID: 36589386
OK. I modified the script from the above link to rename all the folders and subfolders, starting in the folder where the script is located. I marked the line in the code where you can change the starting folder to whatever you like.
Dim sStartFolder
sStartFolder = "."    ' <-- replace this with the path to the folder you want to start in

RenameSubFolders(sStartFolder)

Sub RenameSubFolders(sFolder)
	Dim fso
	Dim fol

	' create the filesystem object
	Set fso = WScript.CreateObject("Scripting.FileSystemObject")
		
	' go thru each files in the folder
	For Each folder In fso.GetFolder(sFolder).SubFolders
		' check if the file name contains underscore
		If InStr(1, folder.Name, "_") <> 0 Then
			' replace underscore with space
			sName = Replace(folder.Name, "_", "M")
			' rename the foldere
			folder.Name = sName
		End If
		
		RenameSubFolders(folder.Path)
	Next
End Sub


' echo the job is completed
WScript.Echo "Completed!"

Open in new window

0
 
LVL 1

Author Closing Comment

by:chasmant
ID: 36590442
thanksd will really save time
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction During my participation as a VBScript contributor at Experts Exchange, one of the most common questions I come across is this: "I have a script that runs against only one computer. How can I make it run against a list of computers in …
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses
Course of the Month10 days, 4 hours left to enroll

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question