CreateDirectory, CreateDirectoryEx
VB声明Declare Function CreateDirectory& Lib "kernel32"
Alias "CreateDirectoryA" (ByVal lpNewDirectory As String, lpSecurityAttributes
As SECURITY_ATTRIBUTES)Declare Function CreateDirectoryEx& Lib
"kernel32" Alias "CreateDirectoryExA" (ByVal lpTemplateDirectory As String,
ByVal lpNewDirectory As String, lpSecurityAttributes As
SECURITY_ATTRIBUTES)说明创建一个新目录返回值Long,非零表示成功,零表示失败。会设置GetLastError
参数表
参数 类型及说明
lpTemplateDirectory String,指定一个模板目录的名字,从中复制默认属性(比如目录中文件
的默认压缩方式)。如设为vbNullString,则表示不使用模板
lpNewDirectory String 新目录的名字
lpSecurityAttributes SECURITY_ATTRIBUTES,这个结构定义了目录的安全特性——如果操作系统支持的话
示例程序代码如下:
‘定义结构
Private Type SECURITY_ATTRIBUTES
nLength As Long
lpSecurityDescriptor As Long
bInheritHandle As Long
End Type
‘函数声明
Private Declare Function CreateDirectory& Lib "kernel32" Alias "CreateDirectoryA" (ByVal lpNewDirectory As String, lpSecurityAttributes As SECURITY_ATTRIBUTES)
Private Declare Function CreateDirectoryEx& Lib "kernel32" Alias "CreateDirectoryExA" (ByVal lpTemplateDirectory As String, ByVal lpNewDirectory As String, lpSecurityAttributes As SECURITY_ATTRIBUTES)
Private Sub form_load()
Dim temp As SECURITY_ATTRIBUTES
CreateDirectory "c:\test", temp ‘创建文件夹
End Sub