Location My.Computer.FileSystem.GetDirectories Syntax Dim result As System.Collections.ObjectModel.ReadOnlyCollection( _ Of String) = My.Computer.FileSystem.GetDirectories( _ path[, searchType, wildcard])
path (required; String) The path to the directory that includes the subdirectories to return.
searchType (optional; SearchOption enumeration) The type of search to perform. One of the following Microsoft.VisualBasic.FileIO.SearchOption enumeration values. Value | Description |
---|
SearchAllSubDirectories | Includes all subdirectories found directly under the specified path and all descendant subdirectories below them | SearchTopLevelOnly | Includes only those subdirectories found immediately under the specified path; does not include descendants of those subdirectories |
If this parameter is missing, it defaults to SearchTopLevelOnly.
wildcard (optional; String) A pattern used to match directory names. If missing, all names are matched. Use the asterisk character (*) to match zero or more characters or the question mark character (?) to match exactly one character. Description The GetDirectories method returns a collection of strings, each one the name of a subdirectory within the specified directory. If no directories are found or match the specified wildcard, an empty collection is returned. Usage at a Glance The returned collection is read-only. An exception is thrown if the supplied path is missing or invalid or if an invalid wildcard expression appears. An exception is thrown if the user lacks sufficient file system privileges. Each returned directory name includes the full path to that directory, not just the relative directory name. Example The following example lists all subdirectories in the current directory. Dim dirList As String = "" Dim currentDir As System.Collections.ObjectModel. _ ReadOnlyCollection(Of String) = _ My.Computer.FileSystem.GetDirectories(".") For Each oneSubDir As String In currentDir dirList &= "|" & oneSubDir Next oneSubDir MsgBox("The current directory contains the following " & _ "sub-directories:" & Replace(dirList, "|", vbCrLf)) Related Framework Entries Microsoft.VisualBasic.MyServices.FileSystemProxy.GetDirectories Method Microsoft.VisualBasic.FileIO.FileSystem.GetDirectories Method System.IO.DirectoryInfo.GetDirectories Method See Also CurrentDirectory Property, Drives Property, FileSystem Object, FindInFiles Method, GetDirectoryInfo Method, GetDriveInfo Method, GetFileInfo Method, GetFiles Method, GetTempFileName Method |