VB中有没有自动建立多层目录的方法?
像这样 Makedir( "c:\fdsa\fdsa\fdas\fdas ") 这些目录都不存在的话 它一次就可以都建立出来?
[解决办法]
没有,自己写一段代码。
Public Function MakeDir(Path As String) As Boolean
On Error Resume Next
Dim o_strRet As String
Dim o_intItems As Integer
Dim o_vntItem As Variant
Dim o_strItems() As String
o_strItems() = Split(Path, "\ ")
o_intItems = 0
For Each o_vntItem In o_strItems()
o_intItems = o_intItems + 1
If o_intItems = 1 Then
o_strRet = o_vntItem
Else
o_strRet = o_strRet & "\ " & o_vntItem
MkDir o_strRet
End If
Next
MakeDir = (Err.Number = 0)
End Function
[解决办法]
Private Sub Command1_Click()
MkDirFun "f:\123\456\789\xyz\opq "
End Sub
Private Sub MkDirFun(ByVal sPath)
Dim s As String, x() As String
Dim i As Long
x = Split(sPath, "\ ")
s = x(0)
For i = 1 To UBound(x)
s = s & "\ " & x(i)
If Dir(s, vbDirectory) = " " Then
MkDir s
End If
Next
End Sub