DirectoryInfo.GetDirectories Method ()


Returns the subdirectories of the current directory.

Namespace:   System.IO
Assembly:  mscorlib (in mscorlib.dll)

public DirectoryInfo[] GetDirectories()

Return Value

Type: System.IO.DirectoryInfo[]

An array of DirectoryInfo objects.

Exception Condition

The path encapsulated in the DirectoryInfo object is invalid, such as being on an unmapped drive.


The caller does not have the required permission.


The caller does not have the required permission.

If there are no subdirectories, this method returns an empty array. This method is not recursive.

This method pre-populates the values of the following DirectoryInfo properties:

The following example retrieves all the directories in the root directory and displays the directory names.

using System;
using System.IO;

public class GetDirectoriesTest 
    public static void Main() 

        // Make a reference to a directory.
        DirectoryInfo di = new DirectoryInfo("c:\\");

        // Get a reference to each directory in that directory.
        DirectoryInfo[] diArr = di.GetDirectories();

        // Display the names of the directories.
        foreach (DirectoryInfo dri in diArr)


for reading directories. Associated enumeration: FileIOPermissionAccess.Read

Universal Windows Platform
Available since 10
.NET Framework
Available since 1.1
Available since 2.0
Windows Phone Silverlight
Available since 7.0
Return to top