Accepts a string for a folder path and checks to see if it already exists, if not it creates it usi
Accepts a string for a folder path and checks to see if it already exists, if not it creates it using the FileSystemObject.
API Declarations
'Windows Script Host to gain access to the FileSystemObject.
Rate Accepts a string for a folder path and checks to see if it already exists, if not it creates it usi
(2(2 Vote))
On Error GoTo Err_CreatePath
Dim lCt As Long, sFound As String, l As Long
Dim sTmpPath As String, lPos As Long, fs As FileSystemObject, sTmp As String
Set fs = New FileSystemObject
For lCt = 1 To Len(sPath)
If Mid(sPath, lCt, 1) = "\" Then
sFound = sFound & lCt & ";"
End If
Next lCt
For l = 1 To Len(sFound)
If Mid(sFound, l, 1) <> ";" Then
sTmp = sTmp & Mid(sFound, l, 1)
Else
sTmpPath = Left(sPath, CLng(sTmp))
If Not fs.FolderExists(sTmpPath) Then
fs.CreateFolder (sTmpPath)
End If
sTmp = Empty
End If
Next l
If Not fs.FolderExists(sPath) Then
fs.CreateFolder (sPath)
End If
MsgBox (sPath & " was created successfully!"), vbInformation, "Create Path Successful"
ExitHere:
Set fs = Nothing
Exit Sub
Err_CreatePath:
Select Case Err.Number
Case Else
MsgBox (Err.Number & ": " & Err.Description), vbCritical, "Error Creating Path"
GoTo ExitHere
End Select
End Sub
Accepts a string for a folder path and checks to see if it already exists, if not it creates it usi Comments
No comments yet — be the first to post one!
Post a Comment