How to just display the file name???

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
'Display Files in user directory'
    Public Sub user_directory_Load(ByVal lstFiles As System.Object, ByVal txtDirectory As System.Object) Handles MyBase.Load
        Dim fil As String = "c:\Test\"
        Dim dir As String = "c:\Test\"
        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 holes the files Does Not Exist")
            Exit Sub
        End If
        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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
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.

kodok_gorengCommented:
Imports System.IO
   
    Dim strFileSize As String = ""
    Dim di As New IO.DirectoryInfo("C:\temp")
    Dim aryFi As IO.FileInfo() = di.GetFiles("*.txt")
    Dim fi As IO.FileInfo

    For Each fi In aryFi
        strFileSize = (Math.Round(fi.Length / 1024)).ToString()
        Console.WriteLine("File Name: {0}", fi.Name)
        Console.WriteLine("File Full Name: {0}", fi.FullName)
        Console.WriteLine("File Size (KB): {0}", strFileSize )
        Console.WriteLine("File Extension: {0}", fi.Extension)
        Console.WriteLine("Last Accessed: {0}", fi.LastAccessTime)
        Console.WriteLine("Read Only: {0}", (fi.Attributes.ReadOnly = True).ToString)
    Next
0
X_layerCommented:
Try this:
'Display Files in user directory'
    Public Sub user_directory_Load(ByVal lstFiles As System.Object, ByVal txtDirectory As System.Object) Handles MyBase.Load
        Dim fil As String = "c:\Test\"
        Dim dir As String = "c:\Test\"
        Dim FSO
        Set FSO = CreateObject("Scripting.FileSystemObject")
        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 holes the files Does Not Exist")
            Exit Sub
        End If
        user_directory.Items.AddRange(FSO.GetFileName(IO.Directory.GetFiles(fil)))
        user_directory.Items.AddRange(IO.Directory.GetDirectories(dir))

    End Sub

Open in new window

This is untested code!
0
Pratima PharandeCommented:
you need to use for loop to get file names


Instade of this

 user_directory.Items.AddRange(IO.Directory.GetFiles(fil))

try something like this
For each folderIdx In IO.Directory.GetFiles(fil)    
user_directory.Items.Add(folderIdx.Name)
 Next
0
Exploring SharePoint 2016

Explore SharePoint 2016, the web-based, collaborative platform that integrates with Microsoft Office to provide intranets, secure document management, and collaboration so you can develop your online and offline capabilities.

Easyrider43Author Commented:
Hey Pratima --

it tells me that "Name" is not a member of the string??

why does it tell me this??
0
Pratima PharandeCommented:
0
Easyrider43Author Commented:
I wonder if its cause im using visual studio 2011??
0
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
Easyrider43Author Commented:
Pratima That worked!! except now when I click them to open I get an error saying


Overload resolution failed because no Public 'Start' can be called with these arguments:
    'Public Shared Function Start(fileName As String) As System.Diagnostics.Process':
        Argument matching parameter 'fileName' cannot convert from 'DirectoryInfo' to 'String'.
    'Public Shared Function Start(startInfo As System.Diagnostics.ProcessStartInfo) As System.Diagnostics.Process':
        Argument matching parameter 'startInfo' cannot convert from 'DirectoryInfo' to 'ProcessStartInfo'.

Open in new window

0
Easyrider43Author Commented:
Here is my open page code


Public Sub user_directory_Load(ByVal lstFiles As System.Object, ByVal txtDirectory As System.Object) Handles MyBase.Load
        Dim di As New IO.DirectoryInfo("\\secure\htdocs\onlineoffice\")
        Dim diar1 As IO.FileInfo() = di.GetFiles()
        Dim diar2 As IO.DirectoryInfo() = di.GetDirectories()
        Dim dra As IO.FileInfo
        Dim dir As String = "\\secure\htdocs\onlineoffice\"
        'list the names of all files in the specified directory
        
        If Not Directory.Exists(dir) Then
            MessageBox.Show("Directory That holds the files Does Not Exist", dir)
            Exit Sub
        End If
        For Each dra In diar1
            user_directory.Items.Add(dra)
        Next
        For Each dra2 In diar2
            user_directory.Items.Add(dra2)
        Next

    End Sub

    'Open the file when clicked'
    Private Sub user_directory_MouseDoubleClicked(ByVal sender As System.Object, ByVal e As System.Object) Handles user_directory.MouseDoubleClick
        Process.Start(user_directory.SelectedItem)
    End Sub

Open in new window

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.