Re: MkDir, maybe an old one
Try this...
I have not included error handling which I am sure you can take care of...
vb Code:
Private Sub Command1_Click()
Dim StrFullPath As String, Myarray() As String
'~~> Change this to the relevant path
StrFullPath = "C:\Level1\Level2\Level3"
Myarray = Split(StrFullPath, "\")
MyNewPath = Myarray(0)
For i = 1 To UBound(Myarray)
'~~> Create Paths
MkDir MyNewPath & "\" & Myarray(i)
MyNewPath = MyNewPath & "\" & Myarray(i)
Next i
End Sub
Re: MkDir, maybe an old one
Use this API call:
Code:
Private Declare Function MakeSureDirectoryPathExists Lib "imagehlp.dll" ( _
ByVal lpPath As String) As Long
Make sure lpPath ends with "\"
Re: MkDir, maybe an old one
Quote:
Originally Posted by
anhn
Make sure lpPath ends with "\"
This is important...if you don't have the trailing "\" you will not receive an error or any other indication that it didn't work. However, without that "\" the folders will not be created.
Re: MkDir, maybe an old one
Example from APIGuide:
Code:
Private Declare Function SHCreateDirectoryEx Lib "shell32" Alias "SHCreateDirectoryExA" (ByVal hwnd As Long, ByVal pszPath As String, ByVal psa As Any) As Long
Private Sub Form_Load()
'KPD-Team 2000
'URL: http://www.allapi.net/
'E-Mail: [email protected]
'create the directory 'c:\test\dir\hello\something\apiguide\'
SHCreateDirectoryEx Me.hwnd, "c:\test\dir\hello\something\apiguide\", ByVal 0&
End Sub
Re: MkDir, maybe an old one
Quote:
Originally Posted by Hack
Quote:
Originally Posted by anhn
Make sure lpPath ends with "\"
This is important...if you don't have the trailing "\" you will not receive an error or any other indication that it didn't work. However, without that "\" the folders will not be created.
That's good to be mentioned.
I make a sub like this:
Code:
Sub MakeDeepDir(ByVal sPath As String)
MakeSureDirectoryPathExists sPath & "\"
End Sub
You can pass in sPath with or without trailing "\" because it is accepted if the path ends with "\\".
Unlike the classic MkDir, if the directory already existed, MakeSureDirectoryPathExists() will do nothing and not generate an error.