Function CreateDir(strDir As String) As Integer ' called to create new multi-subfolder directories / folders Dim StrConst As String Dim strDirCurr As String ' current folder being tested/created Dim strNextDir As String ' next subfolder under strDirCurr Dim errnumber As Integer ' error number during folder create Dim errstring As String strConst = "" strDirCurr = "" strNextDir = "" Dim strSvrPath As String ' server drive/name prefix Dim posFolderStart As Integer ' server/drive end and folder starting point On Error Goto ProcessError ' check for \\ of UNC path (e.g. \\servernm\ as start) If (Instr(1, strDir, "\\") =1) Then ' positive match, get the next slash position and recreate strDir posFolderStart = Instr(3, strDir, "\") If (posFolderStart >3) Then ' have a directory past server name strSvrPath = Left(strDir, posFolderStart) strDir = Mid$(strDir, posFolderStart + 1) End If Goto Start End If ' check for drive letter (e.g. "e:\" as start) If (Instr(1, strDir, ":\") =2) Then ' positive match, get the next slash position and recreate strDir ' have a directory past drive letter & colon strSvrPath = Left(strDir, 3) strDir = Mid$(strDir, 4) Goto Start End If ' if made it this far, path did not include a server name (\\servernm\" nor a drive letter (c:\) as it's starting point ' return failure CreateDir = 0 Exit Function Start: If (Instr(1, strDir, "\") > 0) Then strDirCurr = Strleft(strDir, "\") strNextDir = Strright(strDir, "\") Else ' no more slashes, stop CreateDir = 1 Exit Function End If ' determine if need to make directory, ie. does it exist If (Dir(strSvrPath & strConst & strDirCurr, 16) = "") Then Print "creating folder: " & strSvrPath & strConst & strDirCurr & "
" ' doesn't exist, make it Mkdir strSvrPath & strConst & strDirCurr End If SkipNextFolder: strConst = strConst & strDirCurr & "\" ' set working copy to next subfolder strDir = strNextDir Goto Start ' loop ProcessError: errnumber = Err errstring = Error$ Print "Error creating folder, " & strDirCurr & ". Err #: " & Cstr(errnumber) & ", Err Desc: " & errstring & "." ' return something other than 1 CreateDir = 0 Resume SkipNextFolder Exit Function End Function