How to display the file name only vs the whole path

What I have displays the whole path to the file name and I want just the file name to appear in the list box, any ideas on how I could change this code to just display the file name and not the whole path to each file?? in stead of


I it just to show


here is what i have
Public Sub user_directory_Load(ByVal lstFiles As System.Object, ByVal txtDirectory As System.Object) Handles MyBase.Load

        If Not Directory.Exists(dir) Then
            MessageBox.Show("Directory Does Not Exist")
            Exit Sub
        End If
        If Not Directory.Exists(fil) Then
            MessageBox.Show("Directory That holds the files Does Not Exist")
            Exit Sub
        End If
        For Each files In IO.Directory.GetFiles(fil)

    End Sub

Open in new window

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Pratima PharandeCommented:
if you are using no need to use filesystemobject
use this

 Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        ' make a reference to a directory
        Dim di As New IO.DirectoryInfo("c:\")
        Dim diar1 As IO.FileInfo() = di.GetFiles()
        Dim dra As IO.FileInfo

        'list the names of all files in the specified directory
        For Each dra In diar1
    End Sub

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Try this
foreach (string f in System.IO.Directory.GetFiles("Your directory"))
The same will be for the directories, using System.IO.Directory.GetDirectories
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
VB Script

From novice to tech pro — start learning today.