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.
Posted
Updated 4-Aug-13 6:41am
v5
Comments
[no name] 4-Aug-13 11:53am    
http://msdn.microsoft.com/en-us/library/07wt70x2.aspx

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
VB
For Each f As String In FileIO.FileSystem.GetFiles(My.Application.Info.DirectoryPath & "\Letters\test"))
            ComboBox1.Items.Add(f)
        Next


[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
VB
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))
Next
 
Share this answer
 
v2
Comments
Pouya Mozafar 4-Aug-13 14:33pm    
Thank you so much but i need just filenames it added this to my combobox:
h:\test\test\bin\debug\Letters\test.inf
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\")
ComboBox1.Items.Add(f)
Next
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 http://msdn.microsoft.com/en-us/library/db5x7c0d.aspx?cs-save-lang=1&cs-lang=vb#code-snippet-1[^]
[no name] 4-Aug-13 15:10pm    
Just as an FYI, the Path class has a method for that, instead of all that splitting. http://msdn.microsoft.com/en-us/library/system.io.path.getfilenamewithoutextension.aspx
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