Return the names of files that match the specified search pattern in CSharp

Description

The following code shows how to return the names of files that match the specified search pattern.

Example


  /*from  ww w  .  jav a2 s . c o  m*/
  
  
     


using System;
using System.IO;

class Test 
{
    public static void Main() 
    {
        try 
        {
            // Only get files that begin with the letter "c."
            string[] dirs = Directory.GetFiles(@"c:\", "c*");
            Console.WriteLine("The number of files starting with c 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