DirectoryInfo::GetDirectories Method ()
.NET Framework (current version)
Returns the subdirectories of the current directory.
Assembly: mscorlib (in mscorlib.dll)
| 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 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 ); } }
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
Available since 10
.NET Framework
Available since 1.1
Silverlight
Available since 2.0
Windows Phone Silverlight
Available since 7.0
Show: