This documentation is archived and is not being maintained.

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

The My.Computer.FileSystem.GetFiles Method returns the names of files as a read-only collection of strings, which can be parsed with the Split Function (Visual Basic).

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.

    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
    
Show: