This application is going to display folder contents and also compares contents of two folders. I am using web application to display folder contents. By using this application, we can compare two folders easily. This application will display files not common to both folders.
First create a web application in VB.NET, name it as Folderviewer. Next import System.IO namespace. Next create UI as shown below. Here I used 4 listboxes, 2 textboxes, 1 button and some labels:

Next Button_click event and copy this code:
Try
ListBox1.Items.Clear()
Dim path As String = TextBox3.Text
For Each f As String In Directory.GetFiles(path)
Dim filename As String = f.Substring(f.LastIndexOf("\") + 1)
Dim fn_withoutextn As String = filename.Substring(0, filename.IndexOf("."))
ListBox1.Items.Add(fn_withoutextn.ToString)
Next
ListBox2.Items.Clear()
fillsecond()
showdiffA()
showdiffB()
Label5.Text = String.Empty
Catch ex As System.Exception
Label5.Text = (ex.Message).ToString
End Try
Definition for method fillsecond is:
Private Sub fillsecond()
For Each f As String In Directory.GetFiles(TextBox4.Text)
Dim filename As String = f.Substring(f.LastIndexOf("\") + 1)
Dim fn_withoutextn As String = filename.Substring(0, filename.IndexOf("."))
ListBox2.Items.Add(fn_withoutextn.ToString)
Next
End End Sub
Definition for method showdiffA is:
Private Sub showdiffA()
ListBox3.Items.Clear()
For Each f As String In Directory.GetFiles(TextBox3.Text)
If Not File.Exists(TextBox4.Text + f.Substring(f.LastIndexOf("\") + 1)) Then
Dim filename As String = f.Substring(f.LastIndexOf("\") + 1)
Dim fn_withoutextn As String = filename.Substring(0, filename.IndexOf("."))
ListBox3.Items.Add(fn_withoutextn)
End If
Next
Label3.Text = "Files not present in " + TextBox4.Text
End Sub
Definition for method showdiffB is:
Private Sub showdiffB()
ListBox4.Items.Clear()
For Each f As String In Directory.GetFiles(TextBox4.Text)
If Not File.Exists(TextBox3.Text + f.Substring(f.LastIndexOf("\") + 1)) Then
Dim filename As String = f.Substring(f.LastIndexOf("\") + 1)
Dim fn_withoutextn As String = filename.Substring(0, filename.IndexOf("."))
ListBox4.Items.Add(fn_withoutextn)
End If
Next
Label4.Text = "Files not present in " + TextBox3.Text
End Sub
Run the application, specify folder path in each TextBox, and click Show button.
It will display files not common to both folders as shown below:

NOTE: THIS ARTICLE IS CONVERTED FROM C# TO VB.NET USING A CONVERSION TOOL. ORIGINAL ARTICLE CAN BE FOUND ON C# CORNER (http://www.c-sharpcorner.com/).