VBA Code to rename Folders in directory

I need help writting VBA code to rename folder "memo" to "memos" in all locations on my drive.
Can someone suggest how to do it in Access VBA
Who is Participating?
ArkConnect With a Mentor Commented:
Add reference to Microsoft Scripting Runtime
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."
End Sub

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
         Exit Sub
      End If
      For Each fld In rootFolder.SubFolders
         RenameFoldersUnder fld, oldName, newName
      Next fld
      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
      End If
   End If
   Set fld = Nothing
End Sub

Open in new window

Alexander Eßer [Alex140181]Software DeveloperCommented:
Jeffrey CoachmanMIS LiasonCommented:
Meaning you have a folder maned "Memo" in various locations (folders/subfolders)  all over one drive?

How many do you have?
It may be easier (*and safer*) to do this manually...
(I did not examine that code carefully, but it may not differentiate between files and folders
Thus you could rename *anything* (files and folder) that even contain the string "Memo")

Again, I try not to rely on automation for things this "destructive" (cannot be undone, cannot track what was done)
If there are even 50 or so, I would try to do this manually.  This might take a few minute, versus possibly hours manipulating the code to get it bug free

Besides, ...how would you actually "test" this destructive code before running it on your actual drive?

maximyshkaAuthor Commented:
i don't know how many where i have it... It should be aroun 1K, so no way i am going to do it without code.
Jeffrey CoachmanMIS LiasonCommented:
Then I am sure the links Alex140181 posted can set you on your path....

Question has a verified solution.

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.

All Courses

From novice to tech pro — start learning today.