Sub RenameFolders()
Const Z = "tocsndfsshdwsdncshsskfsef"
Const MaxLenName As Integer = 260
Const Path = "C:\test\"
''------------------------------------
Dim FSO As Object, LR&, i&, j&, TempPath As String, Status As String
Dim DA As Object, DB As Object
Dim R As Excel.Range
''------------------------------------
Set DA = VBA.CreateObject("Scripting.Dictionary")
Set DB = VBA.CreateObject("Scripting.Dictionary")
Set FSO = VBA.CreateObject("Scripting.FileSystemObject")
''------------------------------------
Set R = Range("A2")
LR = R(Rows.Count - R.Row, 1).End(xlUp).Row - R.Row + 1
If LR <= 0 Then Exit Sub
''------------------------------------
' For i = 1 To LR
' If R(i, 2).Value Like "*:\*" Then
' Select Case True
' Case Len(Split(R(i, 1).Value, "\")(UBound(Split(R(i, 1).Value, "\")))) > MaxLenName
' Status = "Length Name Folder too long!!!"
' Case Else:
' DA(R(i, 1).Value) = R(i, 2).Value
' DB(R(i, 2).Value) = R(i, 1).Value
' End Select
' Else
' Status = "Name Folder not vailed!!!"
' End If
'' Next
For i = 1 To LR
DA(CStr(R(i, 1).value)) = CStr(R(i, 2).value)
DB(CStr(R(i, 2).value)) = CStr(R(i, 1).value)
Next
Do Until DB.Count <= 0
If DA.exists(DB.Keys(0)) Then
k = k + 1
FSO.MoveFolder Path & DB.Keys(0), Path & Z & k
DB(DA.item(DB.Keys(0))) = Z & k
DA.Remove DB.Keys(0): DA.Remove DB.Items(0)
End If
FSO.MoveFolder Path & DB.Items(0), Path & DB.Keys(0)
If DA.exists(DB.Items(0)) Then DA.Remove DB.Items(0)
DB.Remove DB.Keys(0)
Loop
Set DA = Nothing
Set DB = Nothing
Set FSO = Nothing
End Sub