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.
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
How to: Search for a String in an Array of Strings (Visual Basic)
How to: Parse File Paths in Visual Basic