Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

filename without extension in VB.NET

Posted on 2004-08-24
6
Medium Priority
?
985 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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:
Fahad Mukhtar earned 2000 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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

Tech or Treat!

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

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

Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
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.
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …

636 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