Edit

Share via


FileSystemProxy.GetDirectories Method

Definition

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

Overloads

GetDirectories(String)

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

GetDirectories(String, SearchOption, String[])

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

GetDirectories(String)

Source:
FileSystemProxy.vb
Source:
FileSystemProxy.vb
Source:
FileSystemProxy.vb

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

public:
 System::Collections::ObjectModel::ReadOnlyCollection<System::String ^> ^ GetDirectories(System::String ^ directory);
public System.Collections.ObjectModel.ReadOnlyCollection<string> GetDirectories (string directory);
member this.GetDirectories : string -> System.Collections.ObjectModel.ReadOnlyCollection<string>
Public Function GetDirectories (directory As String) As ReadOnlyCollection(Of String)

Parameters

directory
String

Name and path of directory.

Returns

Read-only collection of the path names of subdirectories within the specified directory.

Exceptions

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 \\.\).

directory is Nothing or an empty string.

The specified directory does not exist.

The specified directory points to an existing file.

The path exceeds the system-defined maximum length.

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

The user lacks necessary permissions to view the path.

The user lacks necessary permissions.

Examples

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.

Remarks

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

See also

Applies to

GetDirectories(String, SearchOption, String[])

Source:
FileSystemProxy.vb
Source:
FileSystemProxy.vb
Source:
FileSystemProxy.vb

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

public:
 System::Collections::ObjectModel::ReadOnlyCollection<System::String ^> ^ GetDirectories(System::String ^ directory, Microsoft::VisualBasic::FileIO::SearchOption searchType, ... cli::array <System::String ^> ^ wildcards);
public System.Collections.ObjectModel.ReadOnlyCollection<string> GetDirectories (string directory, Microsoft.VisualBasic.FileIO.SearchOption searchType, params string[] wildcards);
member this.GetDirectories : string * Microsoft.VisualBasic.FileIO.SearchOption * string[] -> System.Collections.ObjectModel.ReadOnlyCollection<string>
Public Function GetDirectories (directory As String, searchType As SearchOption, ParamArray wildcards As String()) As ReadOnlyCollection(Of String)

Parameters

directory
String

Name and path of directory.

searchType
SearchOption

Whether to include subfolders. Default is SearchOption.SearchTopLevelOnly.

wildcards
String[]

Pattern to match names.

Returns

Read-only collection of the path names of subdirectories within the specified directory.

Exceptions

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 \\.\).

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

The specified directory does not exist.

The specified directory points to an existing file.

The path exceeds the system-defined maximum length.

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

The user lacks necessary permissions to view the path.

The user lacks necessary permissions.

Examples

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.

Remarks

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

See also

Applies to