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

c:\test\hello.php

I it just to show

hello.php

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)
            user_directory.Items.Add(files)
        Next
        user_directory.Items.AddRange(IO.Directory.GetFiles(fil))
        user_directory.Items.AddRange(IO.Directory.GetDirectories(dir))

    End Sub

Open in new window

LVL 1
Easyrider43Asked:
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 vb.net 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
            ListBox1.Items.Add(dra)
        Next
    End Sub
0

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
s___kCommented:
Try this
foreach (string f in System.IO.Directory.GetFiles("Your directory"))
            {
                Console.WriteLine(System.IO.Path.GetFileName(f));
            }
0
s___kCommented:
The same will be for the directories, using System.IO.Directory.GetDirectories
0
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.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.