VBA rename directory

cgmojoco

Well-known Member
Joined
Jan 15, 2005
Messages
699
Hi there-

Is there a quick way to rename all instances of a directory "09-08" in a specified folder?

I need to rename all of the folders named "09-08" to "08-09" within any subdirectory of a specified folder....

Any help appreciated in advance!
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
Try this. Please heed the warnings.
In passing, this is a good example of how we can easily amend existing code by using a modular approach in the first place.
Rich (BB code):
'==============================================================================
'- ROUTINE TO *RENAME* SPECIFIED FOLDERS
'==============================================================================
'- ADAPT THE CODE FOUND IN http://www.mrexcel.com/forum/showthread.php?t=266783
'- REPLACE THE EXISTING SUB WITH THE ONE BELOW
'- This example changes folders called "09-08" to "08-09"
'- Brian Baulsom September 2008
'==============================================================================
'- ** This code is untested in its present state !!! **
'- I strongly suggest that you temporarily copy the "BaseFolder" folder and contents
'- to another location until you are sure that this works correctly !!!
'- Test a single folder first (Make "BaseFolder" a single folder)
'==============================================================================
'- SUBROUTINE : GET SUBFOLDERS OF SPECIFIED FOLDER
'- AMENDED TO CHANGE SPECIFIED FOLDER NAMES
'==============================================================================
Private Sub ShowFolderList(FolderSpec)
    Dim f, f1, fc, s
    Set f = FSO.GetFolder(FolderSpec)
    Set fc = f.subfolders
    '------------------------------
    Dim NewFolderName As String
    NewFolderName = "08-09"
    '--------------------------------------------------------------------------
    '- CHECK SUBFOLDER COUNT
    If fc.Count = 0 Then
        Exit Sub
    Else
    '--------------------------------------------------------------------------
    '- LOOP FOLDERS
        For Each f1 In fc
            '==================================================================
            '- CHECK FOLDER NAME
            '==================================================================
            FolderName = f1.path
            Application.StatusBar = FolderName
            '- CHANGE NAME
            If FolderName = "09-08" Then
                Name FolderName As NewFolderName    ' change the folder name
            End If
            ' MySheet.Cells(ToRow, 1).Value = FolderName ' DON'T NEED THIS LINE (?)
            ' ShowFileList (FolderName)                  ' DON'T NEED THIS LINE (?)
            '==================================================================
            '- CALL SELF TO GET ANY SUBFOLDERS IN THIS SUBFOLDER
            ShowFolderList (FolderName)
            '-------------------------------------------------------------------
        Next
    End If
    '---------------------------------------------------------------------------
End Sub
'== END OF SUB =================================================================
 
Upvote 0

Forum statistics

Threads
1,215,079
Messages
6,122,998
Members
449,092
Latest member
masterms

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top