EASY STRING Q???????????

Posted on 2005-04-15
Last Modified: 2010-04-24
I have a string array that holds file paths but is nothing more then a file path with a file at the end of it.


How can I get the name of the text file so everything to the right of the last "\"???  When the file path to the file could be longer or shorter??  
Question by:macros14
    LVL 12

    Accepted Solution

    Dim fi as New IO.FileInfo(strPath)


    That's one of many ways
    LVL 12

    Expert Comment


    'as above, strPath contains the full filename

    dim i as integer = strPath.LastIndexOf("\")
    Dim filename as string = ""

    If i >= 0 Then
        filename = strPath.Substring(i+1)
        filename = strPath
    End if

    LVL 85

    Expert Comment

    by:Mike Tomlinson
    Another possibility:

    Dim fullPathFileName As String = "C:\mydir\myfile.ext"
    Dim fileName As String = System.IO.Path.GetFileName(fullPathFileName)

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to improve team productivity

    Quip adds documents, spreadsheets, and tasklists to your Slack experience
    - Elevate ideas to Quip docs
    - Share Quip docs in Slack
    - Get notified of changes to your docs
    - Available on iOS/Android/Desktop/Web
    - Online/Offline

    Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
    Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
    Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    10 Experts available now in Live!

    Get 1:1 Help Now