Login or Sign Up to become a member!
LessThanDot Sit Logo

LessThanDot

Community Wiki

Less Than Dot is a community of passionate IT professionals and enthusiasts dedicated to sharing technical knowledge, experience, and assistance. Inside you will find reference materials, interesting technical discussions, and expert tips and commentary. Once you register for an account you will have immediate access to the forums and all past articles and commentaries.

LTD Social Sitings

Lessthandot twitter Lessthandot Linkedin Lessthandot friendfeed Lessthandot facebook Lessthandot rss

Note: Watch for social icons on posts by your favorite authors to follow their postings on these and other social sites.

Navigation

Google Ads

VB.Net: getting a file's extension from a string

From Wiki

Jump to: navigation, search

YOu could use regex or many other complex algorithms but .net has a better way in the system.io namespace.

  1. Imports System.IO
  2.  
  3. Module Module1
  4.  
  5.     Sub Main()
  6.         Dim d As DirectoryInfo = New DirectoryInfo("c:\")
  7.         For Each File As FileInfo In d.GetFiles()
  8.             Console.WriteLine(Path.GetExtension(File.FullName))
  9.         Next
  10.         Console.ReadLine()
  11.     End Sub
  12.  
  13. End Module

The magic happens in the Path.GetExtension bit. And I know File.Extension would give the same result in this case, but I was trying to prove a point ;-).

512 Rating: 2.8/5 (5 votes cast)