%REM Function MakeDir Description: Create a directory with the specified path. Parent directories are also created, if they don't exist. %END REM Sub MakeDir(ByVal strDir$) Dim stack$ ' the list of directories we need to create Dim parts, i%, ptr% strDir = Replace(strDir, "\", "/") ' / works on all OS and simplifies our code. strDir = Replace(strDir, "//", "/") If Right$(strDir, 1) = "/" Then strDir = StrLeftBack(strDir, "/") On Error 76 GoTo parentDoesNotExist MkDir strDir ' if we got here, it worked. Exit Sub parentDoesNotExist: ' failed because parent directory doesn't exist. Build an array of directories to attempt. Resume theLoop theLoop: parts = Split(strDir, "/") For i = 1 To UBound(parts) parts(i) = parts(i-1) & "/" & parts(i) Next ptr = UBound(parts) - 1 ' ptr is index of directory to try to create. On Error 76 GoTo backup tryAnother: MkDir parts(ptr) ' if we get here the create succeeded, and we only have to go forward in the list. On Error GoTo 0 For i = ptr+1 To UBound(parts) MkDir parts(i) Next Exit Sub backup: ptr = ptr - 1 If ptr >= 0 Then If parts(ptr) = "" Then GoTo backup Resume tryAnother End If Error Err, Error ' ran out of higher level directories to try. End Sub