Results 1 to 6 of 6

Thread: [RESOLVED] trim path from filename

  1. #1

    Thread Starter
    Lively Member Amerigo's Avatar
    Join Date
    Dec 2008
    Location
    PSR B1620-26 c-1
    Posts
    126

    Resolved [RESOLVED] trim path from filename

    I am trying to trim the path from a filename. With the following code, it returns "My Documents" where I should be getting "Test.txt". if I change the 1 to a 4 I get what I'm looking for, but that's not going to work if I'm working with a file deeper into subdirectories.
    I need it to display the name of the file regardless of location or file type. Any ideas?
    Code:
        Private Sub trimname()
            Dim filelabel
            split = current.Split("\")
            filelabel = Trim(split(1))
            Elbow1.ButtonText = filelabel
        End Sub
    Anyone who does not wonder, is either omnipotent or a fool.
    Amerigoware <<<My Projects

  2. #2
    Fanatic Member amrita's Avatar
    Join Date
    Jan 2007
    Location
    Orissa,India
    Posts
    888

    Re: trim path from filename

    Use System.IO.FileInfo and get the fileName from there

    Code:
    Dim MyFileInfo As New System.IO.FileInfo("YOUR FULL PATH")
    MyFileInfo.FileName will give the name.
    thanks
    amrita

  3. #3
    Frenzied Member
    Join Date
    Feb 2008
    Location
    Texas
    Posts
    1,288

    Re: trim path from filename

    Use the FileInfo class:

    vb Code:
    1. Dim filepath as string = "C:\blah\blah2\blah3\blah4\test.txt"
    2. Dim FI as new IO.FileInfo(filepath)
    3.  
    4. Dim NameWithoutPath as String = FI.Name

    Justin
    You down with OOP? Yeah you know me!
    MCAD and MCMICKEYMOUSE (vb.net)

    ----

    If it even kinda helps... rate it : )

    Edit a Multi-page .tif file and save.

  4. #4
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,289

    Re: trim path from filename

    try this:
    Code:
    Dim fullPath as string = "c:\xyz\dcf\test.txt"
    Dim fileName as string = IO.Path.GetFileName(fullPath)
    Let us have faith that right makes might, and in that faith, let us, to the end, dare to do our duty as we understand it.
    - Abraham Lincoln -

  5. #5
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,764

    Re: trim path from filename

    Quote Originally Posted by stanav View Post
    try this:
    Code:
    Dim fullPath as string = "c:\xyz\dcf\test.txt"
    Dim fileName as string = IO.Path.GetFileName(fullPath)
    Agreed.
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  6. #6

    Thread Starter
    Lively Member Amerigo's Avatar
    Join Date
    Dec 2008
    Location
    PSR B1620-26 c-1
    Posts
    126

    Re: RESOLVED>> trim path from filename

    Thank you very much, guys.
    Anyone who does not wonder, is either omnipotent or a fool.
    Amerigoware <<<My Projects

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