You can use your favorite social network to register or link an existing account:
Or use your email address to register without a social network:
Sign in with these social networks:
Or enter your username and password
Forgot your password?
Yes, please link my existing account with for quick, secure access.
No, I would like to create a new account with my profile information.
' --------------------------------------------------------------------------' Function: MkTree' Purpose : Create directories for a given file name' Notes : MkTree "c:\a\b\c\file.txt" would create directories for c:\a\b\c' MkTree "c:\a\b\c\" would create c:\a\b\c' MkTree "c:\a\b\c" would create c:\a\b' --------------------------------------------------------------------------Public Sub MkTree(ByVal strFile As String) ' walk the file and make sure the paths exist Dim strRoot As String Dim strPath As String Dim pos As Integer ' get the root If (InStr(strFile, ":\") = 2) Then strRoot = Left(strFile, InStr(strFile, ":\") + 1) ElseIf (InStr(strFile, "\\") = 1) Then strRoot = Left(strFile, InStr(InStr(strFile, "\\") + 2, strFile, "\")) Else MsgBox "Invalid Root Directory", vbExclamation Exit Sub End If pos = InStr(Len(strRoot) + 1, strFile, "\") While (pos > 0) strPath = Left(strFile, pos) ' Create the directory On Error Resume Next MkDir strPath Debug.Assert Err = 0 Or Err = 75 On Error GoTo 0 pos = InStr(pos + 1, strFile, "\") WendEnd Sub
Comments: (5) Collapse
Hi Rob, That looks like a good one for the UA Code Archive if you haven't submitted it already! Please can you give a quick explanation of the Debug.Assert line. Regards, d
Any reason why you didn't use SHPathPrepareForWrite() from Shell32.dll?
You could also use Shell("mkdir c:\a\b\c\").
David, Thanks! Debug.Assert is used to insert a breakpoint based on some condition. In this case, I'm doing error handling inline so this statement is making sure that the error that was received was 0 (no failure), or 75 (path already exists). If a different error was returned the code would break on the Assert line. This is there for debugging and can be removed. Rob
Thanks for your comment Extremo. I also used this as an example of parsing for something else I was doing, but that API would work as well. Rob
Comments: (loading) Collapse