borderAndreaVB free resources for Visual Basic developersborder

AndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2008 Andrea Tincani
:: Returns the Directory from a complete file path string...

Author  

David Costelloe

Language  

VB5, VB6

Operating Systems  

Windows 95, 98 and NT
Module

Public Function DWCReturnDirectoryOnly(strFileName$) As String
'***************************************************************************
'* Returns Directory Only
'* Usage: strVar = DWCReturnDirectoryOnly("C:\Program Files\mydata.mdb")
'* Returns "C:\Program Files\"
'***************************************************************************

    Dim i As Integer
    Dim sChar As String
    Dim iLastPos As Integer
    Dim iFindPos As Integer
    Dim iFieldPtr As Integer
    Dim strMsg As String
    Dim iFirst As Integer
    Dim lRecordLength As Long
    Dim iFinished As Integer
    Dim dblRate As Double
    Dim intError As Integer
    Dim iLastSlashPos As Integer

    iLastPos = 1
    iFindPos = 1
    iFieldPtr = 0
    iFirst = True
    lRecordLength = Len(strFileName$)
    iFinished = False
    Do While iFindPos > 0
        iFindPos = InStr(iFindPos, strFileName$, "\")
        If iFindPos <> 0 Then
' Found it
            If (iFindPos - iLastPos) > 0 And Not iFirst Then
                iFirst = False
            Else
                If iFirst Then
                    iFirst = False
                End If
            End If
        Else
            If iLastPos < lRecordLength Then
                iFindPos = lRecordLength
            Else
                iFinished = True
            End If
        End If
        If iFinished Then
            DWCReturnDirectoryOnly = Mid(strFileName$, 1, iLastSlashPos)
            Exit Do
        End If
        If (Mid$(strFileName$, iFindPos, 1) = "\") Then
            iLastSlashPos = iFindPos
        End If
        iLastPos = iFindPos + 1
        iFindPos = iFindPos + 1
        iFieldPtr = iFieldPtr + 1
    Loop
End Function

:: Navigation

Home

Files and Disks Tips

Previous Tip

Next Tip

:: Search this site
Google
:: Related Topics
icon 12-09-2006 Re: UNC to a drive letter by steve_w
icon 29-06-2006 Re: How do i determine if the file exist online by admin
icon 18-07-2005 Re: Publishing worries by nubs
icon 07-04-2005 Re: On Which File Should I Run Regsvr32? by matt_1ca
icon 04-10-2004 Problem with Multiple instances by PGatchalian
:: Sponsored Links



Partners: Il portale per lui e lei | Download Actual Software | Free Software Download
borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2008 Andrea Tincaniborder