Attribute VB_Name = "modMakeDir"
Option Explicit





'-----------------------------------------------------------
' SUB: AddDirSep
' Add a trailing directory path separator (back slash) to the
' end of a pathname unless one already exists
'
' IN/OUT: [strPathName] - path to add separator to
'-----------------------------------------------------------
Public Sub AddDirSep(strPathName As String)
    Const gstrSEP_DIR = "\"                         ' Directory separator character
    Const gstrSEP_URLDIR = "/"                      ' Separator for dividing directories in URL addresses.
    If Right(Trim(strPathName), Len(gstrSEP_URLDIR)) <> gstrSEP_URLDIR And _
       Right(Trim(strPathName), Len(gstrSEP_DIR)) <> gstrSEP_DIR Then
        strPathName = RTrim(strPathName) & gstrSEP_DIR
    End If
End Sub

'-----------------------------------------------------------
' FUNCTION: DirExists
' Determines whether the specified directory name exists.
' Returns: True if the directory exists, False otherwise
'-----------------------------------------------------------
Public Function DirExists(ByVal strDirName As String, ceFileSystem As FILECTLCtl.FileSystem) As Boolean
    Dim iFileAttributes As Integer
    On Error Resume Next
    iFileAttributes = ceFileSystem.GetAttr(strDirName)
    If (iFileAttributes And vbDirectory) Then
        DirExists = True
    Else
        DirExists = False
    End If
End Function

Public Sub MakePath(ByVal strPath As String, ceFileSystem As FILECTLCtl.FileSystem)
    Dim iSlashPos As Integer
    Dim strDir As String

    On Error Resume Next
    If DirExists(strPath, ceFileSystem) Then Exit Sub
    iSlashPos = InStr(1, strPath, "\")
    While (iSlashPos <> 0)
        strDir = Mid(strPath, 1, iSlashPos - 1)
        If (Not DirExists(strDir, ceFileSystem)) Then ceFileSystem.MkDir strDir
        iSlashPos = InStr(iSlashPos + 1, strPath, "\")
    Wend
    If (Not DirExists(strPath, ceFileSystem)) Then ceFileSystem.MkDir strPath
    On Error GoTo 0
End Sub

Public Sub CreateDirPath(strPath As String, ceFileSystem As FileSystem)
    If Not DirExists(strPath, ceFileSystem) Then
        MakePath strPath, ceFileSystem
    End If
End Sub



