Experts Exchange connects you with the people and services you need so you can get back to work.
Private fso As New FileSystemObject
Private fldCount As Long
Private Sub Command1_Click()
Dim fldRoot As Folder
Set fldRoot = fso.GetFolder("D:\")
fldCount = 0
RenameFoldersUnder fldRoot, "Temp2", "Temp1"
MsgBox "Done!" & vbCrLf & fldCount & " folder(s) renamed."
Private Sub RenameFoldersUnder(rootFolder As Folder, oldName As String, newName As String)
Dim fld As Folder
On Error Resume Next
If rootFolder.SubFolders.count Then
If Err Then
For Each fld In rootFolder.SubFolders
RenameFoldersUnder fld, oldName, newName
If rootFolder.Name = oldName Then
Dim oldPath As String, newPath As String
oldPath = rootFolder.Path
newPath = Replace(oldPath, oldName, newName)
fso.MoveFolder oldPath, newPath
fldCount = fldCount + 1
Set fld = Nothing
Open in new window
Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.
Have a better answer? Share it in a comment.
Please enter a first name
Please enter a last name
Must be at least 4 characters long.
Join and Comment
From novice to tech pro — start learning today.
Premium members can enroll in this course at no extra cost.
Premium members get this course for $389.00.
Premium members get this course for $31.25.
Premium members get this course for $151.20.
Premium members get this course for $24.94.
Premium members get this course for $37.50.