GetDirectories Method
Collapse the table of content
Expand the table of content

DirectoryInfo::GetDirectories Method ()


Returns the subdirectories of the current directory.

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

array<DirectoryInfo^>^ GetDirectories()

Return Value

Type: array<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 namespace System;
using namespace System::IO;
int main()

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

   // Get a reference to each directory in that directory.
   array<DirectoryInfo^>^diArr = di->GetDirectories();

   // Display the names of the directories.
   Collections::IEnumerator^ myEnum = diArr->GetEnumerator();
   while ( myEnum->MoveNext() )
      DirectoryInfo^ dri = safe_cast<DirectoryInfo^>(myEnum->Current);
      Console::WriteLine( dri->Name );


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
© 2016 Microsoft