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
maximyshkaAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Alexander Eßer [Alex140181]Software DeveloperCommented:
0
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?

JeffCoachman
0
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.
0
Jeffrey CoachmanMIS LiasonCommented:
Then I am sure the links Alex140181 posted can set you on your path....
;-)

JeffCoachman
0
ArkCommented:
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
         Err.Clear
         Exit Sub
      End If
      For Each fld In rootFolder.SubFolders
         RenameFoldersUnder fld, oldName, newName
      Next fld
   Else
      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

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.