用dir判断是否存在,但MkDir,不能创建多级目录,需用循环创建
Function MDir(ByVal folder As String)
Dim s() As String, i As Long, t As String
s = Split(folder, "\")
t = s(0)
For i = 1 To UBound(s)
t = t & "\" & s(i)
If Dir(t, vbDirectory) = "" Then MkDir t
Next
End Function
'用API里面的方法:
'如果是调用kernel32的函数的话,路径最长不超过260。在260个字符数中你喜欢弄几层是几层。但是如果是使用ntdll的函数的话,限制就要小些,只要目录名不长于256就行了。
Private Declare Function MakeSureDirectoryPathExists Lib "imagehlp.dll" (ByVal DirPath As String) As Long
Function CreatePath(byval fileStr as string)
If Dir(fileStr, vbDirectory) = "" Then MakeSureDirectoryPathExists fileStr
End Sub