Code: using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.IO; //add this namespace //add a button with name btnSelectPath //add a button with name btnCountSubDir //add a FolderBrowserDialog with name FolderBrowser //add a ListBox with name txtFolderPath //add a TextBox with name txtFolderPath //add two Label one of those with name lblCount namespace CountSubdirectories { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void btnSelectPath_Click(object sender, EventArgs e) { FolderBrowser.ShowDialog(); txtFolderPath.Text = FolderBrowser.SelectedPath; } private void btnCountSubDir_Click(object sender, EventArgs e) { string[] subdir = Directory.GetDirectories(txtFolderPath.Text); foreach (string s in subdir) lstSubDir.Items.Add(s); lblCount.Text = lstSubDir.Items.Count.ToString(); } } }