Wow, that was great! Now (and I guess I should have included this in my original question), can I create the "invalid" directory?
** Edit **
Split from Dynamic hyperlinks.
** Edit **
Split from Dynamic hyperlinks.
mkDir "C:\Test"
Public Function MakeDir(ByVal strPath As String) As Boolean
'creates a directory independent of whether the parent directory exists
'Code by TheSmileyOne
'Version 0.1
'Date 2010-05-19
'Known issues
'No error handling for cases such as network drives, with restricted permissions to create folders.
'No input validation
On Error GoTo err_Handler
'Check if rightmost char is a \
If Right(strPath, 1) = "\" Then
'Strip it
strPath = Left(strPath, Len(strPath) - 1)
End If
'Check if each individual directory exists, and if not, create it
Dim strSplitPath() As String
ReDim strSplitPath(UBound(Split(strPath, "\")))
strSplitPath = Split(strPath, "\")
Dim intI As Integer
Dim strCombined As String
For intI = 0 To UBound(strSplitPath)
If intI <> 0 Then strCombined = strCombined & "\"
strCombined = strCombined & strSplitPath(intI)
If Dir(strCombined, vbDirectory) = "" Then
MkDir strCombined
End If
Next
'Succes
MakeDir = True
Exit Function
MakeDir = False
MsgBox "Error " & Err.Number & " occured." & vbNewLine & Err.Description
End Function
mkDir "C:\Test"
Public Function MakeDir(ByVal strPath As String) As Boolean
'creates a directory independent of whether the parent directory exists
'Code by TheSmileyOne
'Version 0.1
'Date 2010-05-19
'Known issues
'No error handling for cases such as network drives, with restricted permissions to create folders.
'No input validation
On Error GoTo err_Handler
'Check if rightmost char is a \
If Right(strPath, 1) = "\" Then
'Strip it
strPath = Left(strPath, Len(strPath) - 1)
End If
'Check if each individual directory exists, and if not, create it
Dim strSplitPath() As String
ReDim strSplitPath(UBound(Split(strPath, "\")))
strSplitPath = Split(strPath, "\")
Dim intI As Integer
Dim strCombined As String
For intI = 0 To UBound(strSplitPath)
If intI <> 0 Then strCombined = strCombined & "\"
strCombined = strCombined & strSplitPath(intI)
If Dir(strCombined, vbDirectory) = "" Then
MkDir strCombined
End If
Next
'Succes
MakeDir = True
Exit Function
MakeDir = False
MsgBox "Error " & Err.Number & " occured." & vbNewLine & Err.Description
End Function
Comment