Skip to: Site menu | Main content

Login

Name: 
Password:
Remember me?
Register

MakeDirectory

written by Mark Rowlinson - Last updated Sep 2005

The MkDir function can sometimes be annoying as it will only create the final folder specified in a path so you need to check that the other folders exist before doign so. This procedure improves on this by making all required folders for a given path.

 
Sub MakeDirectory(strPath As String) 
     
    Dim s() As String 
    Dim d As String 
    Dim i As Integer 
    s = Split(strPath, "") 
    d = s(0) 
    i = 1 
    Do 
        d = d & "" & s(i) 
        If Dir(d, vbDirectory) = "" Then MkDir d 
        i = i + 1 
    Loop Until i > UBound(s) 
End Sub