Click here to Skip to main content
15,946,012 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to add all file names from folder"Letters" to my combobox like this code:
ComboBox3.Items.Add(FileIO.FileSystem.GetName(My.Application.Info.DirectoryPath & "\Letters\test"))
But this code just add "test" to my combobox but I want to add all file names from folder "Letters".
I want just file names.
Give me some examples.
Please help Me.
Thank You.
Updated 4-Aug-13 6:41am
[no name] 4-Aug-13 11:53am

1 solution

With credit to ThePhantomUpvoter whose comment is pointing you to the correct method...

You have used .GetName which is correctly returning the name of the folder.

If you want the filenames you need to use .GetFiles for example
For Each f As String In FileIO.FileSystem.GetFiles(My.Application.Info.DirectoryPath & "\Letters\test"))

[Edit - OP wants just the first part of the file name - no path, no suffix]

Here is one (clunky) way of getting just the first part of the filename
For Each f As String In FileIO.FileSystem.GetFiles("c:\\develop")
    Dim s() As String
    s = f.Split(New Char() {".", "\\"})
    ComboBox1.Items.Add(s(s.GetUpperBound(0) - 1))
Share this answer
Pouya Mozafar 4-Aug-13 14:33pm    
Thank you so much but i need just filenames it added this to my combobox:
But I need JUST test
And if I want to add the texts of files ,I should use this code ????
For Each f As String In FileIO.FileSystem.ReadAllText(My.Application.Info.DirectoryPath & "\Letters\")
CHill60 4-Aug-13 15:05pm    
I updated my solution with one method of getting just that bit of the filename

and for the 2nd bit of your comment it depends if you want each line from your file as a separate entry on the combobox - see this[^]
[no name] 4-Aug-13 15:10pm    
Just as an FYI, the Path class has a method for that, instead of all that splitting.
CHill60 4-Aug-13 15:18pm    
Thanks - couldn't remember the flippin' class name! (Hence "clunky") must be my age :-)
Pouya Mozafar 4-Aug-13 15:08pm    
Thank you so much you are the best.
what about the texts of the files?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900