How to create a defined hierarchy of folders in bulk

Creating a directory structure looks like a pain if the hierarchy is big and you need to create them in bulk. If you ever faced this problem then you are on right post.


A 6-8 line code in excel (vba) or in fact any other language makes it easy. Let's see how easy it is.
Suppose you want to create this structure

Assumptions

# Each row should have 1 name. It can be a master folder, sub-folder or any further child.
# Folder names are valid and accurate
# Sub folders of a folder follow the pattern as shown in image. An immediate child should be one column next to parent folder. Multiple child folders may have same column but should be in different row.





Solution

1. Open VB editor in Excel and create a module

2. Copy- paste this code
Sub genericFolders()
On Error Resume Next
For i = 1 To ActiveSheet.UsedRange.Rows.Count
xc = Range("XFD" & i).End(xlToLeft).Column
    If xc = 1 Then
        fpath = Cells(i, xc).Value
    Else
        fpath = Cells(Cells(i, xc - 1).End(xlUp).Row, xc - 1).Value & "/" & Cells(i, xc).Value
        Cells(i, xc).Value = fpath
    End If
   
    MkDir ("D:\MAIN\" & fpath)
    If Err.Number <> 0 Then
        Err.Clear
    End If
Next
End Sub



3 .Run