CreateDirectory用法的完整代码

2020-07-12 科技 150阅读
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
声明:你问我答网所有作品(图文、音视频)均由用户自行上传分享,仅供网友学习交流。若您的权利被侵害,请联系fangmu6661024@163.com