Visual Basic List subdirectories in a directory
How can I do this? I 开发者_如何学Gotried doing looking in
My.Computer.Filesystem
and
FileIO.Filesystem
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.
Use System.IO.DirectoryInfo
or System.IO.Directory
class methods.
精彩评论