首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > VB >

创建多层目录,该怎么处理

2012-03-02 
创建多层目录我用filecopy“e:\a\b\c\d.txt”,“c:\ww\b\c\d.txt”将文件(e:\a\b\c\d.txt)拷贝到目录(c:\ww\b\

创建多层目录
我用filecopy   “e:\a\b\c\d.txt”,“c:\ww\b\c\d.txt”
将文件(e:\a\b\c\d.txt)拷贝到目录(c:\ww\b\c\d.txt)中去,但是C盘中不存在b这个文件夹,我是不是必须用       CreateFolder一级一级的创建这个路径呢?

有没有什么函数直接创建这个目录       c:\ww\b\c\    


[解决办法]

'连续创建不存在的目录,如:可以直接创建 "c:\asdfsd\asd\sf\efad "多级目录
Function MkDirEx(ByVal s As String) As Boolean
On Error GoTo ErrHandle
Dim a() As String
Dim i As Long

If Dir(s, vbDirectory) <> " " Then MkDirEx = True: Exit Function
s = LCase(Replace(s, "/ ", "\ "))

If Left(s, 2) <> "\\ " Then
'if it is a local path
a = Split(s, "\ "): s = " "
'must has a valid drive in the path string
If Not (a(LBound(a)) Like "[a-z]: ") Then Exit Function
If Dir(a(LBound(a)) & "\ ", vbDirectory) = " " Then Exit Function
s = a(LBound(a))
Else
'if it is a network shared path
s = Mid(s, 3)
a = Split(s, "\ ")
s = "\\ " & a(LBound(a))

End If
For i = LBound(a) + 1 To UBound(a)
s = s & "\ " & a(i)
If Dir(s, vbDirectory) = " " Then
MkDir s
End If
Next
MkDirEx = True
Exit Function
ErrHandle:
Err.Clear
MkDirEx = False
End Function
[解决办法]
这个简单啦,你要建一百层的目录还是一句搞定.
shell "cmd.exe /c md C:\1\2\3\4\5\6\7\8\........ " ,vbhide

热点排行