Matthewj
Matthewj

Reputation: 2022

Visual Basic List subdirectories in a directory

How can I do this? I tried doing looking in

My.Computer.Filesystem

and

FileIO.Filesystem

Upvotes: 3

Views: 4854

Answers (2)

Tim
Tim

Reputation: 28520

Try this:

System.IO.Directory.GetDirectories("Directory Path");

This will return a String() (string array) of the subdirectories.

Directory.GetDirectories Method

Note that there are 3 overloads for this method. The first one (shown above) simply takes the supplied directory and lists subdirectories.

GetDirectories(path, searchPattern) takes the path and a search pattern (like "my*" - which would list all directories that start with "my").

GetDirectories(path, searchPattern, searchOption) is like the second one, but searchOption indicates whether or not to search subdirectories within the current directory. Values are SearchOption.TopDirectoryOnly or SearchOption.AllDirectories.

Upvotes: 3

KV Prajapati
KV Prajapati

Reputation: 94625

Use System.IO.DirectoryInfo or System.IO.Directory class methods.

Upvotes: 0

Related Questions