Reputation: 121
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
Upvotes: 0
Views: 43
Reputation: 3301
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();
Upvotes: 2