Search Tools Links Login

Filename from Path


Given a fully qualified path and filename, returns only the filename.

Module

Function GetFileName(fname As String) As String
    Dim i As Long

    On Error Resume Next
    For i = Len(fname) To 1 Step -1
        If Mid(fname, i, 1) = "\" Then
            Exit For
        End If
    Next i
    GetFileName = Trim(Mid(fname, i + 1))
End Function

Usage

Private Sub Command1_Click()
    ' Good for removing the path
    MsgBox GetFileName("C:\Windows\System\moricons.dll")
End Sub

About this post

Posted: 2019-09-30
By: DavidCostelloe
Viewed: 251 times

Categories

Visual Basic 6

Attachments

No attachments for this post

Special Instructions

This code originally appeared on AndreaVB.com, and has been republished here with the permission of Andrea Tincani.


Loading Comments ...

Comments

No comments have been added for this post.

You must be logged in to make a comment.