Results 1 to 3 of 3

Thread: How to separate the filename from a path?

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Nov 2001
    Posts
    1,384

    How to separate the filename from a path?

    I know this is so easy but I can't think how to do it. I have a path e.g. C:\SomeDirectory\SomeSubDirectory\SomeFile.Ext

    I want to break this into 2 strings
    Str1: C:\SomeDirectory\SomeSubDirectory
    Str2: SomeFile.Ext
    Mel

  2. #2
    Retired VBF Adm1nistrator plenderj's Avatar
    Join Date
    Jan 2001
    Location
    Dublin, Ireland
    Posts
    10,359
    VB Code:
    1. '' Jamie Plenderleith
    2. ''
    3.  
    4.  
    5. '' Return the path of a given full path to a file
    6. ''
    7. Private Function returnPathOfFile(ByVal strFile As String) As String
    8.     returnPathOfFile = Left(strFile, InStrRev(strFile, "\"))
    9. End Function
    10.  
    11. '' Return the filename of a given full path to a file
    12. ''
    13. Private Function returnNameOfFile(ByVal strFile As String) As String
    14.     returnNameOfFile = Mid(strFile, InStrRev(strFile, "\") + 1)
    15. End Function
    Microsoft MVP : Visual Developer - Visual Basic [2004-2005]

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Nov 2001
    Posts
    1,384
    Cheers
    Mel

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