Search

List subdirectories

This C# code snippet lists all of the subdirectories of the current directory (folder).
using System;
using System.IO;
 
class DirectorySubfolders
{
   public static void Main()
   {
   string directoryString = 
      Directory.GetCurrentDirectory(); 
   int i = directoryString.LastIndexOf ('\\');
   directoryString = directoryString.Remove (i, directoryString.Length - i);
   Console.WriteLine ("Directories under \"{0}\" are...", directoryString);
   string[] directories = Directory.GetDirectories (directoryString);
   foreach (string directory in directories)
      { Console.WriteLine ("Subdirectory: \"{0}\"", directory); }
   }
}