How can I make listbox that contains items from some folder...
For example:
I have 10 .txt files in 1 folder. In my program when I click button "view" there is a listbox that contains names of that .txt files.
Printable View
How can I make listbox that contains items from some folder...
For example:
I have 10 .txt files in 1 folder. In my program when I click button "view" there is a listbox that contains names of that .txt files.
vb Code:
ListBox1.Items.Clear() ListBox1.Items.AddRange(IO.Directory.GetFiles(folderPath, "*.txt"))
It works but I want only name of the file to be shown in listbox
IO.Path.GetFileName(ListBox1.Items(i).ToString)
vb Code:
Dim fbd As New FolderBrowserDialog If fbd.ShowDialog = DialogResult.OK Then Dim di As New IO.DirectoryInfo(fbd.SelectedPath) ListBox1.Items.Clear() ListBox1.Items.AddRange(di.GetFiles("*.txt")) End If
Without FolderBrowserDialog. Just like first time but i need only name of the files...
vb Code:
Dim di As New IO.DirectoryInfo("c:\folderPath") ListBox1.Items.Clear() ListBox1.Items.AddRange(di.GetFiles("*.txt"))
will give you the filenames. i.e.
filename.txt
to display just the filenames without the extension:
vb Code:
ListBox1.Items.Clear() for each filename as string in IO.Directory.GetFiles(folderPath, "*.txt") ListBox1.Items.Add(IO.Path.GetFileNamewithoutextension(filename)) next
Thank you ! :)