我用mkdir来建立目录,但现在有个问题就是如果我建立的地方已经有这个目录了,就会出错有没有办法来先判断再建立, 还有个问题就是我如何在一个目录下建立一个二级目录呢?
解决方案 »
- dim a as new xx 和 dim a as xx set a=new xx 区别
- 响应“CSDN公告:七月初将强制结帖! ”,《CSDN论坛浏览器》新增自动揭帖给分功能
- 如何把msflexgrid的某一列的内容全部改成红色或绿色!?在线等!
- 求一个算法,以下是要求!
- SQL 语句:(高分相送)
- 高手请进~在线等!!!!很急
- 可否让一个可执行程序在我的一个form或者上面的一个控件里面执行。
- 请教一个小问题
- Mscomm32的缓冲区在被读入后会自动刷新吗?谢谢
- Instr()和InstrRev()返回的值怎么是一样的?????
- 怎样用对一个文件进行base64编码?谢了,最好有源码!
- 急呀,大虾们救救我!!!
用dir
If Dir("文件名", vbDirectory) Then
MsgBox "存在"
Else
MsgBox "不存在"
End If
mkdir 一级目录名\二级目录名
mkdir "c:\temp\temp1" '在c:\temp目录下建temp1子目录
mkdir "c:\temp\temp1\temp2" '在c:\temp\temp1目录下建temp2子目录
mkdir "c:\temp\temp1" '在c:\temp目录下建temp1子目录
mkdir "c:\temp\temp1\temp2" '在c:\temp\temp1目录下建temp2子目录
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