Results 1 to 4 of 4

Thread: VB Snippet - File Name from Path

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Aug 2000
    Location
    IN SILENCE
    Posts
    6,441

    VB Snippet - File Name from Path

    VB Code:
    1. Function GetFileName(FileName As String) As String
    2.      
    3.      Dim i As Integer
    4.      
    5.      On Error Resume Next
    6.      
    7.      For i = Len(FileName) To 1 Step -1
    8.  
    9.        If Mid(FileName, i, 1) = "\" Then
    10.  
    11.          Exit For
    12.  
    13.        End If
    14.  
    15.     Next
    16.      
    17.      GetFileName = Mid(FileName, i + 1)
    18.  
    19. End Function
    Remaining quiet down here !!!

    BRAD HAS GIVEN ME THE ULTIMATIVE. I have chosen to stay....

  2. #2
    New Member
    Join Date
    Feb 2003
    Location
    Newton, MA, USA
    Posts
    7
    Here's my way
    VB Code:
    1. Function GetFileName (FileName As String) As String
    2.   FileName = StrReverse(FileName)
    3.   Dim Pieces() As String
    4.   Pieces() = Split(FileName, "\", 2)
    5.   GetFileName = StrReverse(Pieces(0))
    6. End Function
    Last edited by ffejy; Mar 1st, 2003 at 09:40 PM.

  3. #3
    Fanatic Member
    Join Date
    Jun 2000
    Location
    Forest
    Posts
    545
    There are some errors in you code ffejy - On the array. Very unique method once it worked.


    I like to use something like this.

    MsgBox Mid(FileName, InStrRev(FileName, "\") + 1)
    Bird of Prey

    Mr. Bald Eagle.
    [img][/img]

  4. #4
    New Member
    Join Date
    Feb 2003
    Location
    Newton, MA, USA
    Posts
    7
    Oops, thanks for pointing that out Hawk, fixed now. Your method is the shortest
    Jeff

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width