Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

How would you create a directory using VB6?


Drag0n
 Share

Recommended Posts

I ripped this from my source, it has UNC support if required.

```
'-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Function DriveExist(ByVal Drive As String) As Boolean
'Example, C: , will remove the \ Automatically!
'On error, will return false
'-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
On Error GoTo ForceFalse
Dim FSO
Set FSO = CreateObject("Scripting.Filesystemobject")

    If FSO.DriveExists(Drive) = True Then
        DriveExist = True
    Else
        DriveExist = False
    End If
Set FSO = Nothing
Exit Function

ForceFalse:
DriveExist = False
Set FSO = Nothing

End Function

'-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Function CreateFolder(ByVal Path As String) As Boolean
' Returns false if failed, True if ftw.
' Loops through and makes sure all parent folders exist too!
'-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

Dim FSO
Dim Parse, currentpath As String
Dim PathLen, Currentlen, i As Long

Set FSO = CreateObject("Scripting.Filesystemobject")

PathLen = Len(Path)
Parse = Split(Path, "\")

If Mid(Path, 1, 2) = "\\" Then ' if its a UNC path!

    Currentlen = (Len(Parse(2)) + 3)
    currentpath = "\\" & Parse(2) & "\"

    i = 3

Else                            ' if its a local path!

    Currentlen = (Len(Parse(1)) + 1)
    currentpath = Parse(1) & "\"

    If DriveExist(Parse(0)) = False Then ' check to see if the drive exists
        GoTo Failed
    End If

    i = 1

End If

    Do
        currentpath = currentpath & Parse(i) & "\"

        If FolderExist(currentpath) = False Then
            FSO.CreateFolder (currentpath)
        End If

        Currentlen = Currentlen + Int(Len(Parse(i))) + 1
        i = i + 1

    Loop Until Currentlen >= PathLen

CreateFolder = True
Set FSO = Nothing
Exit Function

Failed:
CreateFolder = False
Set FSO = Nothing

End Function
```
Link to comment
Share on other sites

```
If CreateFolder(App.path & "\Test folder\Another test folder") = True then
MsgBox "Created folder successfully!", VbInformation + VbOkOnly, "Info!"
Else
MsgBox "Failed to create the folder!", VbCritical + VbOkOnly, "Error!"
End if
```
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...