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 |