by Programming Innovations (7 Submissions)
Category: Files/File Controls/Input/Output
Compatability: VB 6.0
Difficulty: Unknown Difficulty
Originally Published: Mon 19th August 2002
Date Added: Mon 8th February 2021
Rating: (1 Votes)
Feed this function the full path to a file and tell it what you would like to return, filename; file path; file extension, and it will tell
API Declarations
sfpExtension = 0
sfpName = 1
sfpPath = 2
End Enum
Dim x As Long
Select Case tPart
Case Is = 0 ' Extension
For x = 0 To Len(sFile)
If Left(Right(sFile, x), 1) = "." Then
GetFilePart = Right(sFile, x - 1)
Exit For
End If
Next x
Case Is = 1 ' Name
For x = 0 To Len(sFile)
If Left(Right(sFile, x), 1) = "\" Or Left(Right(sFile, x), 1) = "/" Then
GetFilePart = Right(sFile, x - 1)
Exit For
End If
Next x
Case Is = 2 ' Path
If Right(sFile, 1) <> "\" Then
For x = 0 To Len(sFile)
If Left(Right(sFile, x), 1) = "\" Then
GetFilePart = UCase(Left(sFile, Len(sFile) - (x - 1)))
Exit For
End If
Next x
Else: GetFilePart = UCase(sFile)
End If
End Select
If GetFilePart = "" Then
GetFilePart = sFile
End If
Exit Function
' Error Handler
CheckForErrors:
If Err.Number = 3021 Then
Resume Next
ElseIf Err.Number <> 0 Then
msgbox err.number & ", " & err.description
resume next
end if
End Function
No comments have been posted about Feed this function the full path to a file and tell it what you would like to return, filename; fil. Why not be the first to post a comment about Feed this function the full path to a file and tell it what you would like to return, filename; fil.