VB用mkdir在当前目录建立文件夹
答案:4 悬赏:70 手机版
解决时间 2021-02-19 00:02
- 提问者网友:低吟詩仙的傷
- 2021-02-18 10:23
If Dir(App.Path & "\Database\a", vbDirectory) = "" ThenMkDir (App.Path & "\Database\a")End If我的代码是这样当程序生成EXE文件就提示找不到路径要怎么修改。谢谢
最佳答案
- 五星知识达人网友:玩家
- 2021-02-18 11:26
应该是Database不存在,建了Database再建a就行了
If Dir(App.Path & "\Database", vbDirectory) = "" Then
MkDir (App.Path & "\Database")
End if
If Dir(App.Path & "\Database\a", vbDirectory) = "" Then
MkDir (App.Path & "\Database\a")
End if
If Dir(App.Path & "\Database", vbDirectory) = "" Then
MkDir (App.Path & "\Database")
End if
If Dir(App.Path & "\Database\a", vbDirectory) = "" Then
MkDir (App.Path & "\Database\a")
End if
全部回答
- 1楼网友:纵马山川剑自提
- 2021-02-18 13:38
你要先建立Database目录
再建立Database\a
Private Sub Form_Click()
p1 = App.Path & "\Database"
p2 = App.Path & "\Database\a"
If Dir(p1, vbDirectory) = "" Then MkDir p1
If Dir(p2, vbDirectory) = "" Then MkDir p2
End Sub
做个函数给你吧
示例:
Private Sub Form_Click()
If MakeDirectory("d:\1\2\3") Then MsgBox "ok" Else MsgBox "err"
End Sub
Public Function MakeDirectory(ByVal Path As String) As Boolean
On Error GoTo ErrHandle
Dim c As String
Dim p As String
For i = 1 To Len(Path)
c = Mid(Path, i, 1)
If c = "/" Or c = "\" Then
p = Left(Path, i - 1)
If Dir(p, vbDirectory) = "" Then MkDir p
End If
Next i
If Dir(Path, vbDirectory) = "" Then MkDir Path
MakeDirectory = True
ErrHandle:
End Function
- 2楼网友:詩光轨車
- 2021-02-18 13:27
试试这样
If Dir(iif(right(App.Path,1)="\",app.path,app.path+"\") & "Database\a", vbDirectory) = "" Then
MkDir (iif(right(App.Path,1)="\",app.path,app.path+"\") & "Database\a")
- 3楼网友:北方的南先生
- 2021-02-18 11:49
open app.path & "\12\123.txt" for output as #1
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯