C# Directory EnumerateDirectories(String)

Description

Directory EnumerateDirectories(String) Returns an enumerable collection of directory names in a specified path.

Syntax

Directory.EnumerateDirectories(String) has the following syntax.


public static IEnumerable<string> EnumerateDirectories(
  string path
)

Parameters

Directory.EnumerateDirectories(String) has the following parameters.

  • path - The directory to search.

Returns

Directory.EnumerateDirectories(String) method returns <

Example

The following example enumerates the top-level directories in a specified path.


//from w  ww  . j ava2  s. c  o  m
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;

class Program
{
    private static void Main(string[] args)
    {
       string dirPath = @"\\archives";

       List<string> dirs = new List<string>(Directory.EnumerateDirectories(dirPath));

       foreach (var dir in dirs)
       {
           Console.WriteLine("{0}", dir.Substring(dir.LastIndexOf("\\") + 1));
       }
    }
}




















Home »
  C# Tutorial »
    System.IO »




BinaryReader
BinaryWriter
Directory
DirectoryInfo
DriveInfo
File
FileInfo
FileStream
MemoryStream
Path
StreamReader
StreamWriter
StringReader
StringWriter