• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1005
  • Last Modified:

filename without extension in VB.NET

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
vihar123
Asked:
vihar123
1 Solution
 
imu79Commented:
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
 
vihar123Author Commented:
oFileInfo.Name prints filename with extension . "countrylist____23456.html"

0
 
Fahad MukhtarDistinguished EngineerCommented:
       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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
RonaldBiemansCommented:
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
 
DotNetLover_BaanCommented:
hi there... use System.IO.Path

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

-Baan
0
 
DotNetLover_BaanCommented:
guess , you don't like single line code ...  :(
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now