VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Feed this function the full path to a file and tell it what you would like to return, filename; fil

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

Rate Feed this function the full path to a file and tell it what you would like to return, filename; fil



    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


Download this snippet    Add to My Saved Code

Feed this function the full path to a file and tell it what you would like to return, filename; fil Comments

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.

Post your comment

Subject:
Message:
0/1000 characters