Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
 
 
Old Pages
 
Old Index
Site Map
What's New
 
Books
How To
Tips & Tricks
Tutorials
Stories
Performance
Essays
Links
Q & A
New in VB6
Free Stuff
Pictures
 
 
 
 
 
 
 
TitleMake the directories in a complete path
Keywordsdirectory, path
CategoriesFiles & Directories
 
Use Split to break the path apart at the \ symbols. Loop through the pieces of the path, creating the subdirectories that don't already exist from the directory root down.
 
' Create the complete directory path.
Private Sub MakePath(ByVal path As String)
Dim directories As Variant
Dim i As Integer
Dim new_dir As String
Dim dir_path As String

    ' Break the path into directories.
    directories = Split(path, "\")

    ' Build the subdirectories.
    For i = LBound(directories) To UBound(directories)
        ' Get the next directory in the path.
        new_dir = directories(i)

        ' Make sure the entry is non-empty.
        If Len(new_dir) > 0 Then
            ' Add the new directory to the path.
            dir_path = dir_path & new_dir & "\"

            ' Make sure we don't just have a drive
            ' specification.
            If Right$(new_dir, 1) <> ":" Then
                ' See if the directory already exists.
                If Dir$(dir_path, vbDirectory) = "" Then
                    ' The directory doesn't exist.
                    ' Make it.
                    MkDir dir_path
                End If
            End If
        End If
    Next i
End Sub
 
 
Copyright © 1997-2001 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated