0

I have the code

Me.MetroComboBox1.DataSource = IO.Directory.GetDirectories("C:\sampledir\", "*", IO.SearchOption.TopDirectoryOnly)

Which is supposed to return the names of folders into a combobox, however when I do, the folders come out as "C\sampledir\samplefolder" instead of "samplefolder". Is there any way to fix this?

  • Does this answer your question? [How to get Directories name](https://stackoverflow.com/questions/26364708/how-to-get-directories-name) – Fabio Nov 26 '19 at 08:23
  • Thanks, however I seem to get 'DirectoryInfo' is a class type and cannot be used as an expression. – ICreativeCrum Nov 26 '19 at 08:33
  • 2
    `Dim dirNames = Directory.GetDirectories("Your Path", "*", SearchOption.TopDirectoryOnly).Select(Function(d) Path.GetFileName(d)).ToList()` – Jimi Nov 26 '19 at 08:44
  • take @Jimi code and add `Me.MetroComboBox1.DataSource = dirNames` – TontonVelu Nov 26 '19 at 08:55

1 Answers1

0

This might help you. Return only the name of directory and not her full path

Me.MetroComboBox1.DataSource = IO.Directory.GetDirectories("C:\sampledir\", "*",
                                                                   IO.SearchOption.TopDirectoryOnly).Select(Function(nD) New IO.DirectoryInfo(nD).Name)
G3nt_M3caj
  • 2,497
  • 1
  • 14
  • 16