Imports System.IO

Public Class Form1

    Sub DirAndFilesViewer(ByVal dir As String, ByVal showFiles As Boolean, _

    Optional ByVal level As Integer = 0)

        Dim subdir As String

        Dim fileNm As String


        ' Prints the directroty heading with indentation

        Console.WriteLine(New String("-"c, level * 2) & dir)



            ' Prints the file names with indentation.

            If showFiles Then

                For Each fileNm In Directory.GetFiles(dir)

                    Console.WriteLine(New String(" "c, level * 2 + 2) & fileNm)


            End If

            ' The funciton is called recuresively for each sub directory

            For Each subdir In Directory.GetDirectories(dir)

                Me.DirAndFilesViewer(subdir, showFiles, level + 1)



            ' skips over errors.

        End Try

    End Sub


    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click


    End Sub


    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        Dim DirNm As String

        Dim showFiles As Boolean = False

        DirNm = Me.TextBox1.Text

        If Me.CheckBox1.Checked Then

            showFiles = True


            showFiles = False

        End If

        Me.DirAndFilesViewer(DirNm, showFiles)

    End Sub

End Class