Visual Basic 6 function "dirname"

Go back

Below you'll find the source for the Visual Basic 6 function dirname.

Attribute VB_Name = "modDirname"
' This function is downloaded from:
' http://www.stefanthoolen.nl/archive/vb6-functions/
' 
' You may freely distribute this file but please leave all comments, including this one, in it.
' 
' @Author Stefan Thoolen <mail@stefanthoolen.nl>

Option Explicit

''
' Returns directory name component of path
' Same syntax as the PHP function 'dirname'
' See also: http://www.php.net/manual/en/function.dirname.php
' @param    String  Path        The full path
' @return   String              Only the directory part of the input string
' @author   Stefan Thoolen <mail@stefanthoolen.nl>
Public Function dirname(Path As String) As String
    Dim i As Integer
    i = InStrRev(Replace(Path, "\", "/"), "/")
    If i <= 0 Then Exit Function
    dirname = Left(Path, i - 1)
End Function