'递规地创建目标文件夹
Private Sub CreateDestFolder(ByVal FolderSpec As String)
Dim CurrFld As String
Dim Fsys As New FileSystemObject
If Fsys.FolderExists(FolderSpec) Then
Exit Sub
End If
CurrFld = Fsys.GetParentFolderName(FolderSpec) '获取其父文件夹
If Fsys.FolderExists(CurrFld) Then
Fsys.CreateFolder (FolderSpec)
Else
Call CreateDestFolder(CurrFld)
Fsys.CreateFolder (FolderSpec)
End If
End Sub
Private Declare Function CreateDirectory& Lib "kernel32" Alias "CreateDirectoryA" (ByVal lpNewDirectory As String, lpSecurityAttributes As SECURITY_ATTRIBUTES)
Private Type SECURITY_ATTRIBUTES
nLength As Long
bInheritHandle As Long
lpSecurityDescriptor As Long
End Type
Private Sub Command1_Click()'第一种
Dim my As SECURITY_ATTRIBUTES
CreateDirectory "d:\my", my
End Sub
Private Sub Command2_Click()'第二种
MkDir "d:\my"
End Sub
两种方法:
Private Declare Function CreateDirectory& Lib "kernel32" Alias "CreateDirectoryA" (ByVal lpNewDirectory As String, lpSecurityAttributes As SECURITY_ATTRIBUTES)
Private Type SECURITY_ATTRIBUTES
nLength As Long
bInheritHandle As Long
lpSecurityDescriptor As Long
End Type
Private Sub Command1_Click()'第一种
Dim my As SECURITY_ATTRIBUTES
CreateDirectory "d:\my", my
End Sub
Private Sub Command2_Click()'第二种
MkDir "d:\my"
End Sub