Link to home
Start Free TrialLog in
Avatar of venmarces
venmarcesFlag for Canada

asked on

MS DOS script or .Net Script to rename a list of sub-folders

Hello  

I am looking for a MS-DOS possible or even VBScript or .net script that allows me to rename all Sub-Folders in a specific folder having AAA in their name into sub-folders with BBB.

Thanks
Avatar of Luis Pérez
Luis Pérez
Flag of Spain image

Try this in VB.net:

Imports System.IO

Private Sub RenameFolders()
    Dim startFolder As DirectoryInfo = New DirectoryInfo("c:\your_parent_folder")
    Dim subfolders() As DirectoryInfo = startFolder.GetDirectories("*AAA*")
    For Each subfolder As DirectoryInfo in subfolders
        Dim newDirectory As String = subfolder.FullName.Replace("AAA", "BBB")
        subfolder.MoveTo(newDirectory)
    Next
End Sub

Open in new window

Hope that helps.
SOLUTION
Avatar of oBdA
oBdA

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of venmarces

ASKER

Can I use for multilevels of sub-folders ?
Avatar of oBdA
oBdA

The Powershell script will recurse into all subdirectories.
So I create a VBS File and just Paste your script and I changed the AAA and BBB for what I want to change

Is this the correct way to execute it ?
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial