Solved

Vbscript to go through files

Posted on 2011-09-23
4
293 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
  • 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 500 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Welcome back!  My apologies for taking so long to write part two of this series; it's been a long time coming!  As I promised in Part 1, this article will focus on how to locate those elusive AD properties that you are searching for.  Why is this us…
Hello again, all.  For those of you that have been following along, you'll know that this is my third article on this topic (though it is not Part III).  This article is sort of remedial, and probably the topic with which I should have started the s…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

758 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now