Public Function NewDir(ByVal strPath) As Boolean
Dim dirAttr As VbFileAttribute
dirAttr = vbNormal + vbDirectory + vbReadOnly
If Dir(strPath, dirAttr) <> "" Then
NewDir = True
Exit Function
End If
Dim Pos As Long
Dim strTemp As String
On Error Resume Next
Pos = InStr(1, strPath, "\")
While Pos > 0
strTemp = Left(strPath, Pos - 1)
If Dir(strTemp, dirAttr) = "" Then MkDir strTemp
Pos = InStr(Pos + 1, strPath, "\")
Wend
MkDir strPath
NewDir = (Dir(strPath, dirAttr) <> "")
If Err <> 0 Then Err.Clear
End Function
Public Sub SysErr(ByVal s As String)
If IsAutoRun Then Exit Sub
LimitMsgBoxText s
MsgBox s, vbCritical, "错误提示"
End Sub
Private Sub LimitMsgBoxText(s As String)
Const nMaxLen As Integer = 250
If Len(s) > nMaxLen Then s = Left(s, nMaxLen) & "..."
End Sub
Public Sub KillFile(strFile As String)
If Dir(strFile, vbHidden + vbNormal + vbReadOnly) <> "" Then
SetAttr strFile, vbNormal
Kill strFile
End If
End Sub
Dim dirAttr As VbFileAttribute
dirAttr = vbNormal + vbDirectory + vbReadOnly
If Dir(strPath, dirAttr) <> "" Then
NewDir = True
Exit Function
End If
Dim Pos As Long
Dim strTemp As String
On Error Resume Next
Pos = InStr(1, strPath, "\")
While Pos > 0
strTemp = Left(strPath, Pos - 1)
If Dir(strTemp, dirAttr) = "" Then MkDir strTemp
Pos = InStr(Pos + 1, strPath, "\")
Wend
MkDir strPath
NewDir = (Dir(strPath, dirAttr) <> "")
If Err <> 0 Then Err.Clear
End Function
Public Sub SysErr(ByVal s As String)
If IsAutoRun Then Exit Sub
LimitMsgBoxText s
MsgBox s, vbCritical, "错误提示"
End Sub
Private Sub LimitMsgBoxText(s As String)
Const nMaxLen As Integer = 250
If Len(s) > nMaxLen Then s = Left(s, nMaxLen) & "..."
End Sub
Public Sub KillFile(strFile As String)
If Dir(strFile, vbHidden + vbNormal + vbReadOnly) <> "" Then
SetAttr strFile, vbNormal
Kill strFile
End If
End Sub

本文介绍了一个使用VB.NET创建目录的函数,该函数通过检查路径并递归地创建所有必要的子目录来实现目录创建。
625

被折叠的 条评论
为什么被折叠?



