Gets an array of directories matching the specified search pattern from the current directory in CSharp

Description

The following code shows how to gets an array of directories matching the specified search pattern from the current directory.

Example


  /*from   ww w .ja  v a2 s . c om*/
  
  
     

using System;
using System.IO;

class Test 
{
    public static void Main() 
    {
        try 
        {
            string[] dirs = Directory.GetDirectories(@"c:\", "p*");
            Console.WriteLine("The number of directories starting with p is {0}.", dirs.Length);
            foreach (string dir in dirs) 
            {
                Console.WriteLine(dir);
            }
        } 
        catch (Exception e) 
        {
            Console.WriteLine("The process failed: {0}", e.ToString());
        }
    }
}




















Home »
  C# Tutorial »
    IO »




File Attribute
File Security
Directory Attribute
Directory Recursive
Binary File
Text Field
Buffered IO
Create Copy Delete Move
CSV
Drive
File System Watcher
Isolated Storage
MemoryStream
Serialize
Zip