PBDR.COM

About   -   Contact   -   Purchase   -   Search   -   What's New

 
 
CreatePath Function
This function is used in conjunction with the CopyTree function and its purpose is to create new folders determined by the path passed to it. The function is an extension of the MkDir function with extra code added to ensure a valid path is used. Add the following code to a FileHandling.bas standard module to compile a File Utility function set:
Public Function CreatePath(ByVal Path As String, errnum _
  As Integer) As Boolean
'*************************************************************
'<DESC>		Creates a specified folder.</DESC>
'<RETURN>		Boolean:
'			Success level of function</RETURN>
'<ACCESS>		Public</ACCESS>
'<ARGS>		Path: 
'			Path of new folder
'		</ARGS>
'<USAGE>		blnOK = CreatePath("c:\new folder\test\", 0)
'		</USAGE>
'*************************************************************

    Dim dirnam As String
    Dim n As Integer
    Dim txt As String

    dirnam = Left$(Path, 2)
    txt = Mid$(Path, 4)
    n = InStr(txt, "\")
    Do While n <> 0
        dirnam = dirnam & "\" & Left$(txt, n - 1)
        If Not DirExists(dirnam) Then
            On Error GoTo CreatePath_Err
            MkDir dirnam
        End If
        txt = Mid$(txt, n + 1)
        n = InStr(txt, "\")
    Loop
    CreatePath = True
CreatePath_Exit:
    Exit Function
CreatePath_Err:
    errnum = Err
    CreatePath = False
    Resume CreatePath_Exit

End Function
 

Top of Page

Legal Notice

Ken Howe 2011