by Daniel S Boucher (4 Submissions)
Category: Files/File Controls/Input/Output
Compatability: VB 6.0
Difficulty: Unknown Difficulty
Originally Published: Sat 5th October 2002
Date Added: Mon 8th February 2021
Rating: (1 Votes)
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.
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
No comments have been posted about Accepts a string for a folder path and checks to see if it already exists, if not it creates it usi. Why not be the first to post a comment about Accepts a string for a folder path and checks to see if it already exists, if not it creates it usi.