• Recent Posts

  • Meta

  • Tags

    autocomplete benchmark data cpu cycles directory exists disable beep on enter doevents ebook excel extensions file exists getinputstate gzip high cpu usage intensive task left edge linq mcisendstring microsoft msdn no doevents office open webpage play mp3 play wave right edge scroll textbox shell show icon show notify icon source stop beep on enter system tray text tar textbox text in system tray time consuming tutorials vb 2008 video visual basic.net visual basic 2005 visual studio visual studio 2005 ehancements vs 2005 IDE extensions windows mci
  • « Visual Basic 2008 (and Express Editions) Supports 2.0+ Framework | Home | Microsoft is giving you a peek at the source code for the .NET Librarys! »

    Extract/Return the files Path and Filename without the Extension

    By Jason | September 29, 2007

    Click Star to Rate Post
    1 Star2 Stars3 Stars4 Stars5 Stars (4 votes, average: 4.5 out of 5)
    Loading ... Loading ...


       
    Bookmark and Share

     


     

    Dim filePath As String = "c:\MyDirectory\MYFile.txt"

    Dim extensionPosition As Integer = filePath.LastIndexOf(".")

    Dim filePathNoEx As String = filePath.Substring(0, extensionPosition)

    MsgBox(filePathNoEx) 


      


     

    Popularity: 19% [?]

    Topics: - (.NET All + 05/08) |

    3 Responses to “Extract/Return the files Path and Filename without the Extension”

    1. Rajesh Says:
      October 11th, 2007 at 8:16 am

      Just replace filePath.LastIndexOf(".") with filePath.LastIndexOf("\")

    2. Jason H Says:
      October 12th, 2007 at 10:53 pm

      Hi, This snippet is for someone that WANTs the "Path AND Filename" but NOT the Extension for the filename.

      The code you posted could be used for checking the position of the last slash if you wanted - "the path without the filename" or "filename without the path".

      But I did go ahead and change the slashPosition variable in this code snippet to "extensionPosition" since it sounds more relevent.

      I do thankyou for the comment too :)

      Jason

    3. Trang Says:
      March 6th, 2008 at 2:12 am

      Thanks a lot. This code helps me alot.

    Comments