Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Listing Only SubFolders In C#?

I have some code:

string pathUser = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);
string pathDownload = Path.Combine(pathUser, @"documents\iracing\setups\");
DirectoryInfo dinfo = new DirectoryInfo(pathDownload); // Populates field with all Sub Folders
FileInfo[] Files = dinfo.GetFiles("*.sto");
foreach (FileInfo file in Files)
{
     listBox2.Items.Add(file.Name);
}

I want the subFolders of: documents\iracing\setups\ to be shown, not the files...including the .sto files. All i need is to list the Subfolders....i have no idea how to do that? Thanks!

like image 589
Hunter Mitchell Avatar asked May 19 '12 20:05

Hunter Mitchell


1 Answers

You can try this:

DirectoryInfo directory = new DirectoryInfo(pathDownload);
DirectoryInfo[] directories = directory.GetDirectories();

foreach(DirectoryInfo folder in directories)
     listBox2.Items.Add(folder.Name);
like image 149
Omar Avatar answered Oct 04 '22 23:10

Omar