MakeDir recursive directory creation
Description: Create a directory with the specified path. Parent directories are also created, if
they don't exist.
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
' if we got here, it worked.
parentDoesNotExist: ' failed because parent directory doesn't exist. Build an array of directories to attempt.
parts = Split(strDir, "/")
For i = 1 To UBound(parts)
parts(i) = parts(i-1) & "/" & parts(i)
ptr = UBound(parts) - 1 ' ptr is index of directory to try to create.
On Error 76 GoTo backup
' 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)
ptr = ptr - 1
If ptr >= 0 Then
If parts(ptr) = "" Then GoTo backup
Error Err, Error ' ran out of higher level directories to try.
The MkDir function of LotusScript is limited in that it can only create a single folder in a folder that already exists. This subroutine will, if necessary, create the entire path.
||November 21, 2011 11:48 AM