请教各位vb高手,怎么创建一个6级目录

来源:百度知道 编辑:UC知道 时间:2024/06/01 21:08:34
我想以一个记录的一个字段作为文件名,然后用这个文件名中的12个字符生成一个六级的目录。具体如下:
假如这个文件名是20080522AAAAAAAA1RVBXJ00,我想把其中的9-17、20-22位生成一个六级的目录,即A\AA\AA\AA\A1\BXJ这样的一个目录。
我找到的一段代码是:
Private Sub Form_Click()
If MakeDirectory("d:\A\AA\AA\AA\B") Then
MsgBox "ok"
Else
MsgBox "err"
End If

End Sub

Public Function MakeDirectory(ByVal Path As String) As Boolean
On Error GoTo ErrHandle
Dim c As String
Dim p As String

For i = 1 To Len(Path)
c = Mid(Path, i, 1)
If c = "/" Or c = "\" Then
p = Left(Path, i - 1)
If Dir(p, vbDirectory) = "" Then MkDir p
End If
Next i
If Dir(Path, vbDirectory) = "" Then MkDir Path
MakeDirectory = True
ErrHandle:

End Function

这段代码只能建一个d:\A\AA\AA\AA\B这样的,里面的参数就是具体的数值,不能改。
我想把d:\A\AA\AA\AA\B这几个设成变

其中的9-17、20-22位生成一个六级的目录
有什么规律?
s="20080522AAAAAAAA1RVBXJ00"
dim arr(5)
arr(0)=mid(s,9,1)
arr(1)=mid(s,10,2)
arr(2)=mid(s,12,2)
arr(3)=mid(s,14,2)
arr(4)=mid(s,16,2)
arr(5)=mid(s,20,3)
MakeDirectory "d:\" & join(arr,"\")

把If MakeDirectory("d:\A\AA\AA\AA\B") Then改一下:
dim x1, as string ,x2 as string,x3 as string,x4 as string,x5 as string,x as string
x1="A\"
x2="AA\"
x3="AA\"
x4="AA\"
X5="B"
x="d:\" +x1+x2+x3+x4+x5
If MakeDirectory(x) Then
就可以了。其中每一级目录都可以事先设定。