Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Vbscript to go through files

Posted on 2011-09-23
4
Medium Priority
?
336 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Well hello again!  Glad to see you've made it this far without giving up.  In this, the fourth installment of my popular series, I'm going to cover functions and subroutines, what they are, and why they are useful.  Just in case you stumbled onto th…
This article is the result of a quest to better understand Task Scheduler 2.0 and all the newer objects available in vbscript in this version over  the limited options we had scripting in Task Scheduler 1.0.  As I started my journey of knowledge I f…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses

636 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