Directory.GetDirectories Method | |
Class System.IO.Directory Syntax Dim result( ) As String = Directory.GetDirectories(path[, _ searchPattern[, searchOption]])
path (required; String) A valid path to a directory.
searchPattern (optional; String) A directory specification, optionally including the wildcard characters * and ?.
searchOption (optional; SearchOption enumeration) New in 2005. One of the following Microsoft.VisualBasic.FileIO.SearchOption enumeration members: Member | Description |
---|
AllDirectories | The method returns information about all nested subdirectories. | TopDirectoryOnly | The method returns information about the topmost directory only. |
If omitted, TopDirectoryOnly is used. Description The GetDirectories method returns an array of strings, with each string containing the name of one subdirectory of the specified main directory, optionally matching a pattern. The results can optionally include all nested subdirectories. Usage at a Glance path can be either an absolute path or a relative path from the current directory. path can be either a path on the local system, the path of a mapped network drive, or a UNC path. path cannot contain wildcard characters, but searchPattern can. If searchPattern is specified, the method returns only those directories with names that match the string, which can contain wildcard characters. Otherwise, GetDirectories returns the names of all the subdirectories in the path directory. If the directory specified by path has no subdirectories, or if no directories match searchPattern, an empty array is returned. Example The following code displays all top-level subdirectories of c:\ with names that start with the letter P: Dim thePDirectories( ) As String Dim counter As Integer thePDirectories = Directory.GetDirectories("c:\", "P*") For counter = 0 To UBound(thePDirectories) Console.WriteLine(thePDirectories(counter)) Next counter Version Differences See Also Directory.GetFiles Method, Directory.GetFileSystemEntries Method |