Name
Directory.GetDirectories Method
Class
System.IO.Directory
Syntax
Directory.GetDirectories(path[,searchpattern])
-
path(required; String) A valid path to a directory
-
searchpattern(optional; String) A directory specification, including wildcard characters
Return Value
An array of strings, each element of which is the name of a subdirectory
Description
Returns the names of the subdirectories in a particular directory
Rules at a Glance
pathcan be either an absolute path (a complete path from the root directory to the directory whose subdirectories are to be retrieved) or a relative path (starting from the current directory to the directory whose subdirectories are to be retrieved).pathcan be either a path on the local system, the path of a mapped network drive, or a UNC path.pathcannot contain wildcard characters.If
searchpatternis specified, the method returns only those directories whose names match the string, which can contain wildcard characters. Otherwise,searchpatternreturns the names of all the subdirectories in the target directory specified bypath.If the directory specified by
pathhas no subdirectories, or if no directories matchsearchpattern, an empty array is returned.
Example
The following code displays all subdirectories of c:\ whose names start with the letter P:
Dim sDirs( ) As String
Dim i As Integer
sDirs = Directory.GetDirectories("c:\", "P*")
For i = 0 To UBound(sDirs)
Console.WriteLine(sDirs(i))
NextProgramming Tips and Gotchas
Since GetDirectories can ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access