Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Split Path+File Into Path or File

Folders and Files

Split Path+File Into Path or File

by  MissyEd  Posted    (Edited  )
Public Function SplitFileName(strDocumentNameAndPath As String, strReturn As String) As String
On Error GoTo errorhandler

Dim oFSO As New FileSystemObject
Dim oFile As File

If oFSO.FileExists(strDocumentNameAndPath) Then
Set oFile = oFSO.GetFile(strDocumentNameAndPath)
Select Case UCase$(strReturn)
Case "FILE"
SplitFileName = oFile.Name
Case "PATH"
SplitFileName = oFSO.GetParentFolderName(oFile.Path) & "\"
End Select
Set oFile = Nothing
End If
Set oFSO = Nothing

' Exit = No errors
Exit Function

errorhandler:
Set oFSO = Nothing
SplitFileName = vbNullString
End Function
Register to rate this FAQ  : BAD 1 2 3 4 5 6 7 8 9 10 GOOD
Please Note: 1 is Bad, 10 is Good :-)

Part and Inventory Search

Back
Top