Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All

FileSystem.GetDirectories Method (String)

Returns a collection of strings representing the path names of subdirectories within a directory.

Namespace:  Microsoft.VisualBasic.FileIO
Assembly:  Microsoft.VisualBasic (in Microsoft.VisualBasic.dll)

public static ReadOnlyCollection<string> GetDirectories(
	string directory
)

Parameters

directory
Type: System.String

Name and path of directory.

Return Value

Type: System.Collections.ObjectModel.ReadOnlyCollection<String>
Read-only collection of the path names of subdirectories within the specified directory..

ExceptionCondition
ArgumentException

The path is not valid for one of the following reasons: it is a zero-length string; it contains only white space; it contains invalid characters; or it is a device path (starts with \\.\).

ArgumentNullException

directory is Nothing or an empty string.

DirectoryNotFoundException

The specified directory does not exist.

IOException

The specified directory points to an existing file.

PathTooLongException

The path exceeds the system-defined maximum length.

NotSupportedException

A file or directory name in the path contains a colon (:) or is in an invalid format.

SecurityException

The user lacks necessary permissions to view the path.

UnauthorizedAccessException

The user lacks necessary permissions.

The following table lists an example of a task involving the My.Computer.FileSystem.GetDirectories method.

To

See

List subdirectories with a specific pattern

How to: Find Subdirectories with a Specific Pattern in Visual Basic

The following example returns all the directories in the directory structure that contain the word Logs in their names and adds them to ListBox1.

For Each foundDirectory In My.Computer.FileSystem.GetDirectories(
      My.Computer.FileSystem.SpecialDirectories.MyDocuments,
      True, "*Logs*")

    ListBox1.Items.Add(foundDirectory)
Next

This example requires that you have a ListBox named ListBox1 on your form.

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0, 2.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Show:
© 2015 Microsoft