关于Dir函数的一个问题
Davy 2000-02-16 08:48:00 以下代码中Dir函数为何总是返回空字符(即使该目录已存在),我应该如何判断指定目录是否存在,望各位高手不吝赐教。
'创建指定的目录,成功返回True,失败返回False
'Path----完整的目录路径,例如:C:\picture\big\city\nanjing
Public Function MakeDir(ByVal Path As String) As Boolean
Dim TempPath As String
Dim Pos As Long
On Error GoTo ErrorHand
If Dir(Path) <>"" Then
MakeDir = True
Exit Function
End If
Pos = 4
Do
Pos = InStr(Pos, Path, "\") + 1
If Pos = 1 Then Exit Do
TempPath = Left(Path, Pos - 2)
If Dir(TempPath) = "" Then MkDir (TempPath)
Loop
MkDir (Path)
If Dir(Path) = Path Then
MakeDir = True
Else:
MakeDir = False
End If
Exit Function
ErrorHand:
MakeDir = False
End Function