C# Directory GetDirectories(String, String)
Description
Directory GetDirectories(String, String)
Gets the
names of subdirectories (including their paths) that match the specified
search pattern in the current directory.
Syntax
Directory.GetDirectories(String, String)
has the following syntax.
public static string[] GetDirectories(
string path,
string searchPattern
)
Parameters
Directory.GetDirectories(String, String)
has the following parameters.
path
- The path to search.searchPattern
- The search string to match against the names of files in path. The parameter cannot end in two periods ("..") or contain two periods ("..") followed by DirectorySeparatorChar or AltDirectorySeparatorChar, nor can it contain any of the characters in InvalidPathChars.
Returns
Directory.GetDirectories(String, String)
method returns
Example
The following example counts the number of directories in a path that begin with the specified letter.
//from w w w.j ava 2s . c o m
using System;
using System.IO;
class Test
{
public static void Main()
{
string[] dirs = Directory.GetDirectories(@"c:\", "p*");
Console.WriteLine(dirs.Length);
foreach (string dir in dirs)
{
Console.WriteLine(dir);
}
}
}
The code above generates the following result.