You can use the PathRemoveFileSpec function, available in every version of Windows from 2000 and 98. Here is a VB6 implementation.
Private Declare Function PathRemoveFileSpec Lib "Shlwapi" _
Alias "PathRemoveFileSpecW" (ByVal szPath As Long) As Long
'Convert input file path to drive & directory only. (Supports UNC too) '
Function sPathOnly(ByVal sInput As String) As String
Dim sWorking As String
sWorking = sInput
If (PathRemoveFileSpec(StrPtr(sWorking)) <> 0) Then
'Call succeeded. Trim trailing Null '
sPathOnly = sTrimNull(sWorking)
Else
sPathOnly = sWorking
End If
End Function
'Trim trailing null characters (e.g. from a string returned from an API call) '
Function sTrimNull(ByVal sIn As String) As String
Dim iZeroCharacter As Long
iZeroCharacter = InStr(sIn, Chr$(0))
If iZeroCharacter > 0 Then
sTrimNull = Left$(sIn, iZeroCharacter - 1)
Else
sTrimNull = sIn
End If
End Function
I prefer to avoid the Microsoft Scripting Runtime (including FileSystemObject). In my experience it's occasionally broken on user machines, perhaps because their IT department are paranoid about viruses. There are other useful functions in shlwapi.dll, e.g. for testing whether folders exist or files exist.