How to Change File Extensions in VB.NET

Written by jaime avelar
  • Share
  • Tweet
  • Share
  • Pin
  • Email
How to Change File Extensions in VB.NET
Change file extensions using VB.NET coding. (stock image of binary code sphere image by Ruslana Stovner from

Microsoft Visual Basic.NET, also known as VB.NET, is an object-oriented computer programming language developed by Microsoft. It's commonly used due to its flexibility and ease of use. A file extension identifies the file format of the contents in a file. It's useful to know how to change file extensions in VB.NET in case you need to change extensions of many of files manually.

Skill level:

Other People Are Reading


  1. 1

    Open Microsoft Visual Basic Express, click "New Project..." under the "File" menu, then select "Windows Forms Application." Click "OK."

  2. 2

    Double-click "Button" on the "Toolbox" pane. Double-click "Button1" to open the "Form1.vb"module. Press "Ctrl" and "A" to select code then press "Delete" to remove existing code.

  3. 3

    Copy and paste the following code into your "Form1.vb ":

    Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim my Files As String()
        my Files = IO.Directory.GetFiles("D:\Temp\", "*.txt")
        Dim newFilePath As String
        For Each filepath As String In my Files
            newFilePath = filepath.Replace(".txt", ".html")
            System.IO.File.Move(filepath, newFilePath)
    End Sub

    End Class

  4. 4

    Edit the following line of code with your own path and file extension:

    my Files = IO.Directory.GetFiles("D:\Temp\", "*.txt")

    Edit the following line of code with your existing and new file extensions:

    newFilePath = filepath.Replace(".txt", ".html")

  5. 5

    Press "F5" to run your program, then press "Button1."

Don't Miss

  • All types
  • Articles
  • Slideshows
  • Videos
  • Most relevant
  • Most popular
  • Most recent

No articles available

No slideshows available

No videos available

By using the site, you consent to the use of cookies. For more information, please see our Cookie policy.