Show the Items in the Folder location and not the full directory

44 Views Asked by At

I have an array with of folders in a Directory. I want them displayed in the combo-box but I don't the full directory to display, I just want the folder names in the directory. I haven't been successful with what I have tried

MY CODE

string[] filePaths = Directory.GetDirectories(@"\\Mgsops\data\B&C_Poker_Builds\Release_Location\Integration\SDL\SP\Prima\");

            ProjectDir.DataSource = filePaths;

            ProjectDir.SelectedItem.ToString();

MY RESULT

enter image description here

1

There are 1 best solutions below

0
snow_FFFFFF On BEST ANSWER

Look at the DirectoryInfo class - you can do something like this:

string folder = new DirectoryInfo(path).Name;

To get an array (using System.Linq), you could do the following:

string[] filePaths = Directory.GetDirectories("<yourpath>").Select(d => new DirectoryInfo(d).Name).ToArray();

Or, even use the DirectoryInfo class to enumerate your directories:

DirectoryInfo dir = new DirectoryInfo("<yourpath>");
string[] filePaths = dir.GetDirectories().Select(d => d.Name).ToArray();