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

FileSystemProxy.GetDirectories Method (String, SearchOption, String[])

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

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

public ReadOnlyCollection<string> GetDirectories(
	string directory,
	SearchOption searchType,
	params string[] wildcards
)

Parameters

directory
Type: System.String

Name and path of directory.

searchType
Type: Microsoft.VisualBasic.FileIO.SearchOption

Whether to include subfolders. Default is SearchOption.SearchTopLevelOnly.

wildcards
Type: System.String[]

Pattern to match names.

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.

ArgumentNullException

One or more of the specified wildcard characters is Nothing, an empty string, or contains only spaces.

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.

You can use the wildcards parameter to specify a specific pattern. If you would like to include the contents of subdirectories in the search, set the searchType parameter to SearchAllSubDirectories.

An empty collection is returned if no directories matching the specified pattern are found.

The following table lists examples of tasks 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