CreateFolderStructure: Create Multiple Layers of Folders

When you’re in accounting or corporate finance, Qclose seems to come faster and faster each time! You’ll be able to save time with this Microservice which creates folders in Windows, as many layers deep as you need.

CreateFolderStructure

Sub CreateFolderStructure(ByVal FolderStructure As String)

    Dim FSO As Object: Set FSO = CreateObject("Scripting.FileSystemObject")

    If Right(FolderStructure, 1) = Application.PathSeparator Then
        FolderStructure = Left(FolderStructure, Len(FolderStructure) - 1)
    End If

    Dim ParentPath As String
    If FSO.FolderExists(FolderStructure) = False Then
        ParentPath = Left(FolderStructure, InStrRev(FolderStructure, Application.PathSeparator) - 1)
        If ParentPath <> "" And FSO.FolderExists(ParentPath) = False Then
            CreateFolderStructure ParentPath
        End If
        FSO.CreateFolder FolderStructure
    End If

End Sub
ParameterDescription
FolderStructureThe path you would like to create.

Examples

CreateFolderStructure "Z:\Department\Qclose\2024\1Q\Reports\"

This creates the entire folder structure specified. Let’s assume it’s a new year and the 2024 folder doesn’t exist yet. CreateFolderStructure will create the 2024 folder, then 1Q within it, and Reports within it.

CreateFolderStructure "\\CorporateNetwork\Department\Qclose\2024\1Q\Reports\"

CreateFolderStructure also supports UNC paths.

CreateFolderStructure PutUsername("C:\Users\%USERNAME%\Box\2024\1Q\Reports\")

Consider incorporating PutUsername to create folders within a sync’d collaboration tool like Box, Dropbox, OneDrive, SharePoint, etc.

Scroll to Top