Here's a generic file path parser that I picked up from somewhere:
Function ParsePathElement(ByVal strFullPath As String, _
strElement As String) As String
' Returns the required section of the specified Path
'
' In: strFullPath - a string from which the specified
' Path element is to be extracted
(Drive,Dir,DriveDir,Drive &
' Dir,File,Ext,FileExt)
' Out: a string of the specified Path element
' Usage: ?ParsePathElement("C:\Win95B\readme.txt", "Drive")
Dim Drive As String
Dim Dir As String
Dim File As String
Dim Ext As String
' Parses FullPath and returns required element
Dim i As Integer, f As String, Found As Integer
Drive = left$(CurDir, 2) ' Current drive if none explicitly
specified
Dir = ""
File = ""
Ext = ""
strFullPath = Trim$(strFullPath)
'
' Get drive letter
'
If Mid$(strFullPath, 2, 1) = ":" Then
Drive = left$(strFullPath, 2)
strFullPath = Mid$(strFullPath, 3)
End If
'
' Get directory name
'
f = ""
Found = False
For i = Len(strFullPath) To 1 Step -1
If Mid$(strFullPath, i, 1) = "\" Then
f = Mid$(strFullPath, i + 1)
Dir = left$(strFullPath, i)
Found = True
Exit For
End If
Next i
If Not Found Then
f = strFullPath
End If
'
' Add current directory of selected drive if absolute directory not
specified
'
If Dir = "" Or left$(Dir, 1) <> "\" Then
Dir = Mid$(CurDir(left$(Drive, 1)), 3) & "\" & Dir
End If
'
' Get File name and extension
'
If f = "." Or f = ".." Then
File = f
Else
i = InStr(f, ".")
If i > 0 Then
File = left$(f, i - 1)
Ext = Mid$(f, i)
Else
File = f
End If
End If
Select Case strElement
Case "Drive"
ParsePathElement = Drive
Case "Dir"
ParsePathElement = Dir
Case "DriveDir"
ParsePathElement = Drive & Dir
Case "File"
ParsePathElement = File
Case "Ext"
ParsePathElement = Ext
Case "FileExt"
ParsePathElement = File & Ext
End Select
End Function
--
Arvin Meyer, MCP, MVP
Microsoft Access
Free Access downloads:
http://www.datastrat.com
http://www.mvps.org/access