VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Build a Path That's Shauld Create More Than Directory

by Abdalla Mahmoud (10 Submissions)
Category: String Manipulation
Compatability: Visual Basic 5.0
Difficulty: Beginner
Date Added: Wed 3rd February 2021
Rating: (6 Votes)

Hi All .. This Code Will Create a Path That's Shauld Make More Than One Directory .. For Example When You Call Function :
Call BuildPath ("C:\A1\A2\A3\A4")
It Will Create "C:\A1" and "C:\A1\A2" .etc
It Will Return False If The Drive Doesnt Exist Or For Any Other Error ..
Please Send Me Your Comments ..

Rate Build a Path That's Shauld Create More Than Directory

Function BuildPath(ByVal Path As String) As Boolean
On Error Resume Next
Dim Fnd As Long
Dim Tmp As String
Dim FileSystemObj As Object
Set FileSystemObj = CreateObject("Scripting.FileSystemObject")
If FileSystemObj.DriveExists(FileSystemObj.GetDriveName(Path)) = False Then Exit Function
Path = Path & IIf(Right(Path, 1) = "\", vbNullString, "\")
Fnd = InStr(Path, "\")
Do While Fnd
Tmp = Tmp & Left(Path, Fnd)
Path = Mid(Path, Fnd + 1)
MkDir Tmp
If FileSystemObj.DriveExists(Tmp) = False And FileSystemObj.FolderExists(Tmp) = False Then Exit Function
Fnd = InStr(Path, "\")
Loop
BuildPath = True
End Function
Private Sub Command1_Click()
Call BuildPath("C:\A1\A2\A3\A4\A5\A6\A7")
End Sub

Download this snippet    Add to My Saved Code

Build a Path That's Shauld Create More Than Directory Comments

No comments have been posted about Build a Path That's Shauld Create More Than Directory. Why not be the first to post a comment about Build a Path That's Shauld Create More Than Directory.

Post your comment

Subject:
Message:
0/1000 characters