Solved

Vbscript to go through files

Posted on 2011-09-23
4
323 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 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone 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

This is pretty cool.  The purpose of this VB Script is to help you document where JAR (Java ARchive) files and specifically java class files are located so that you can address issues seen with a client or that you can speak intelligently with a dev…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.

697 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