Solved

filename without extension in VB.NET

Posted on 2004-08-24
6
864 Views
Last Modified: 2008-01-09
Hi

i am having filename as "countrylist____23456.html"

1) i want to extract Only the file Name (NOT Extension)
2)and from the filename for eg.here "countrylist____23456",extract last 5 characters,
in this case "23456"


thanks for your reply

regards
0
Comment
Question by:vihar123
6 Comments
 
LVL 3

Expert Comment

by:imu79
ID: 11883129
you could do something like:

dim oFileInfo as New System.IO.FileInfo("countrylist____23456.html")
debug.WriteLine(oFileInfo.Name)

I'm not sure if the above prints the extension as well.
If it does, you can trim out the extension since the property oFileInfo.Extension gives you the extension string.

hope this helps..
Imran

0
 

Author Comment

by:vihar123
ID: 11883150
oFileInfo.Name prints filename with extension . "countrylist____23456.html"

0
 
LVL 19

Accepted Solution

by:
Desp earned 500 total points
ID: 11883180
       Dim f As New FileInfo("C:\countrylist____23456.html")
        Dim FName As String = f.Name.Substring(0, f.Name.LastIndexOf("."))
        FName = FName.Substring(FName.Length - 5, 5)
        MessageBox.Show(FName)
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 25

Expert Comment

by:RonaldBiemans
ID: 11883289
or

        Dim oFileInfo As New System.IO.FileInfo("c:\C:\countrylist____23456.html")
        Dim g As String = oFileInfo.Name
        g = g.Replace(oFileInfo.Extension.ToString, "")
        g = g.Substring(g.Length - 5)
0
 
LVL 18

Expert Comment

by:DotNetLover_Baan
ID: 11883338
hi there... use System.IO.Path

        MsgBox(System.IO.Path.GetFileNameWithoutExtension("C:\MyDoc01.doc"))

-Baan
0
 
LVL 18

Expert Comment

by:DotNetLover_Baan
ID: 11883800
guess , you don't like single line code ...  :(
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

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 …
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

932 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

13 Experts available now in Live!

Get 1:1 Help Now