Hi Dw

I have folder which has all the files and the folder can have as much files inside as possible so I have created the function which gets all the files inside this folder and populate it on a listbox so now the problem is that it shows with the path to the file on the listbox which is what I want to get rid off. Here is my function code:

Public Function Scan()
Dim ScanFolder() As String
ScanFolder = Directory.GetFiles("C:\examplefolder\", "." , SearchOption.AllDirectories.GetHashCode)

For Each dFile As String In ScanFolder
ListBox1.Items.Add(dFile)

Next

End Function

So the above code displays the full path to the folder but what I want is to display only the names only. Anyone how can help me in this. Thank you.

Sorry for not formatting the codes I'm using a mobile.

Hi
Use the GetFileName function of Path:

Public Sub Scan()
    Dim ScanFolder as string
    ScanFolder = Directory.GetFiles("C:\examplefolder\", "." , SearchOption.AllDirectories.GetHashCode)
    for each dFile as String in ScanFolder
       ListBox1.Items.Add(System.IO.Path.GetFileName(dFile))
    next
End Sub

Also, you seem to be confusing Function with Sub. The simplest way to remember the difference is that in VB.Net, a Sub does something and a Function returns something (different from c# where it is all functions and the equivalent of sub is to return a null). i.e. I would create a Sub like this, Sub PopulateMyList(Byref MyList as ListBox) which I would code to only populate the Listbox, vs Function ReturnSelectedListItem (Byref ListBox) As ListBoxItem which I would code to return the selected listItem.

Ok thank you. I've already used the WebBrowser to view the files and it did the way I wanted it to, it shows the file names, Date modified, Type of file, and lastly size of each file. But thanks again for your help. ;-)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.