« 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
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) |


(4 votes, average: 4.5 out of 5)
October 11th, 2007 at 8:16 am
Just replace filePath.LastIndexOf(".") with filePath.LastIndexOf("\")
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
March 6th, 2008 at 2:12 am
Thanks a lot. This code helps me alot.