[AccessD] Creating SubDirectories

Jurgen Welz jwelz at hotmail.com
Sat Oct 18 15:35:50 CDT 2008


I use the function below.  It assumes that the drive and root path (in our case S:\GOM\) exists, because that is the location of the backend data file.  All paths are relative to that root.  This is why lngI is initialized to 7 in the code.  A full solution should enumerate drives and should check that each or at least the last folder is created (Dir function) should there be a rights issue with a particular drive.
 
No need to use the the scripting runtime library and its file system object.
 
 
Public Function fnCreateBasePath(strCreatePath As String) As Boolean    On Error GoTo ErrorHandler        Dim strPath As String    Dim lngpos As Long
    strCreatePath = Trim$(strCreatePath)    If Right$(strCreatePath, 1) <> "\" Then strCreatePath = strCreatePath & "\"    lngpos = 7    Do Until lngpos = 1        lngpos = InStr(lngpos + 1, strCreatePath, "\")        If lngpos Then            strPath = Left$(strCreatePath, lngpos - 1)            If Not Len(Dir(strPath, vbDirectory)) > 0 Then                MkDir strPath            End If        End If        lngpos = lngpos + 1    Loop    fnCreateBasePath = True
ExitRoutine:    On Error Resume Next    Exit FunctionErrorHandler:    With Err        Select Case .Number            Case Else                MsgBox .Number & vbCrLf & .Description & vbCrLf & vbCrLf & _                " Error in creating Folder:  '" & strCreatePath & "'", _                vbInformation, "Error - fnCreateBasePath"        End Select    End With    'Resume 0    Resume ExitRoutineEnd FunctionCiaoJürgen WelzEdmonton, Albertajwelz at hotmail.com> Date: Sat, 18 Oct 2008 09:14:27 -0700> From: iggy at nanaimo.ark.com> To: accessd at databaseadvisors.com> Subject: [AccessD] Creating SubDirectories> > Hey All> I am wanting to allow the user to indicate a path (for file storage).> The program checks to see if the path exists, if not it notifies the > user that the path doesn't exist and would they like the program to > create it.> I can do this, but rather then reinventing the wheel does anyone know of > a custom function that would loop through the path and create the > necessary folders/directories.> Eg.> C:\One\Two\Three> Directory One doesn't exist so create the full path.> Directory One and Two do exist so create folder Three
_________________________________________________________________




More information about the AccessD mailing list