By David Wiseman (Administrator)Created 14 Jan 2006
My Rating:
Not Rated

Recursive Folder Rename

Language:  VBScript


Windows XP Yes Windows 2003 Yes
Windows 2000 Unknown Windows NT Unknown
Vista Unknown Windows 2008 Unknown

This script renames all the subfolders in a given folder.

e.g. C:\Test\IT Department Documents\ C:\Test\IT Department Reports\ C:\Test\Archive\IT Department Documents\ C:\Test\Archive\IT Department Reports\ If you wanted to replace IT Department with ITC Department Enter C:\Test Then IT Department Then ITC Department You will now have the following folder list: C:\Test\ITC Department Documents\ C:\Test\ITC Department Reports\ C:\Test\Archive\ITC Department Documents\ C:\Test\Archive\ITC Department Reports\ 

Line Numbers: On  Off      Plain Text
Root = inputbox("Please enter the root folder (all subfolders will be renamed)" & vbcrlf & "e.g. C:\TEST")
if Root="" then Canceled

FindStr = inputbox("Please enter the string that you want to find")
if FindStr = "" then Canceled

ReplaceStr = inputbox("Please enter the string that you want to replace it with")
if ReplaceStr = "" then Canceled

set objFSO= createobject("Scripting.FileSystemObject")

EnumFolders Root

Sub EnumFolders(byval Folder)
	set objFolder = objFSO.GetFolder(Folder)
	set colSubfolders = objFolder.Subfolders

	for each objSubfolder in colSubfolders
		NewFolderName = (Replace(, findstr, replacestr))
			If NewFolderName <> objSubFolder.Name Then
				objSubFolder.Name = NewFolderName
			End If
		enumfolders objSubfolder.path

End Sub

sub Canceled
	wscript.echo "Script Canceled"
end sub


Got a useful script? Click here to upload!


  Post Comment
Order By:  
User Comments
Be the first to post a comment!