How to: Determine a File's Extension in Visual Basic

Switch View :
ScriptFree
Visual Studio 2010 - Visual Basic
How to: Determine a File's Extension in Visual Basic

The GetFiles method returns the names of files as a read-only collection of strings, which can be parsed with the Split function.

To determine a file's extension

  • Retrieve the file path or name of the file and the Split function to determine the extension by supplying the delimiter. This example uses the GetFiles method to return the collection of file names in the directory testDirectory and reports each file's extension.

    Visual Basic
    
    For Each foundFile As String In
    My.Computer.FileSystem.GetFiles("C:\TestDir")
        Dim check As String =
        System.IO.Path.GetExtension(foundFile)
        MsgBox("The file extension is " & check)
    Next
    
    
    
See Also

Tasks

Reference