建立目录问题

lingjiadong 2003-08-26 10:05:51
我用mkdir来建立目录,但现在有个问题就是如果我建立的地方已经有这个目录了,就会出错有没有办法来先判断再建立, 还有个问题就是我如何在一个目录下建立一个二级目录呢?
...全文
84 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
lxcc 2003-08-26
  • 打赏
  • 举报
回复
快速建立多级目录

Private Type SECURITY_ATTRIBUTES
nLength As Long
lpSecurityDescriptor As Long
bInheritHandle As Long
End Type
Private Declare Function CreateDirectory Lib "kernel32" _
Alias "CreateDirectoryA" (ByVal lpPathName As String, _
lpSecurityAttributes As SECURITY_ATTRIBUTES) As Long
'函数:
'Call CreateNewDirectory("c:\test\directory\vb\tips\")
Public Sub CreateNewDirectory(NewDirectory As String)
Dim sDirTest As String
Dim SecAttrib As SECURITY_ATTRIBUTES
Dim bSuccess As Boolean
Dim sPath As String
Dim iCounter As Integer
Dim sTempDir As String
iFlag = 0
sPath = NewDirectory

If Right(sPath, Len(sPath)) <> "\" Then
sPath = sPath & "\"
End If
iCounter = 1
Do Until InStr(iCounter, sPath, "\") = 0
iCounter = InStr(iCounter, sPath, "\")
sTempDir = Left(sPath, iCounter)
sDirTest = Dir(sTempDir)
iCounter = iCounter + 1
SecAttrib.lpSecurityDescriptor = &O0
SecAttrib.bInheritHandle = False
SecAttrib.nLength = Len(SecAttrib)
bSuccess = CreateDirectory(sTempDir, SecAttrib)
Loop
End Sub


Private Sub Command1_Click()
Call CreateNewDirectory("c:\test\directory\vb\tips\")
End Sub
射天狼 2003-08-26
  • 打赏
  • 举报
回复
mkdir "c:\temp" '以C盘根目录下建temp目录
mkdir "c:\temp\temp1" '在c:\temp目录下建temp1子目录
mkdir "c:\temp\temp1\temp2" '在c:\temp\temp1目录下建temp2子目录

射天狼 2003-08-26
  • 打赏
  • 举报
回复
mkdir "c:\temp" '以C盘根目录下建temp目录
mkdir "c:\temp\temp1" '在c:\temp目录下建temp1子目录
mkdir "c:\temp\temp1\temp2" '在c:\temp\temp1目录下建temp2子目录

Alicky 2003-08-26
  • 打赏
  • 举报
回复
二级目录。
mkdir 一级目录名\二级目录名
Alicky 2003-08-26
  • 打赏
  • 举报
回复
建目录这前先检查有没有这个目录。
用dir
If Dir("文件名", vbDirectory) Then
MsgBox "存在"
Else
MsgBox "不存在"
End If
lingjiadong 2003-08-26
  • 打赏
  • 举报
回复
就是比方说我想做用dos命令实现就是 md temp 回车 cd temp 回车 md temp1

7,762

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧