Windows apps
Collapse the table of content
Expand the table of content
Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

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
DirectoryNotFoundException

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

SecurityException

The caller does not have the required permission.

UnauthorizedAccessException

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)
            Console.WriteLine(dri.Name);
    }
}

FileIOPermission

for reading directories. Associated enumeration: FileIOPermissionAccess.Read

Universal Windows Platform
Available since 10
.NET Framework
Available since 1.1
Silverlight
Available since 2.0
Windows Phone Silverlight
Available since 7.0
Return to top
Show:
© 2016 Microsoft