C# Directory GetFiles(String)

Description

Directory GetFiles(String) Returns the names of files (including their paths) in the specified directory.

Syntax

Directory.GetFiles(String) has the following syntax.


public static string[] GetFiles(
  string path
)

Parameters

Directory.GetFiles(String) has the following parameters.

  • path - The directory from which to retrieve the files.

Returns

Directory.GetFiles(String) method returns

Example

The following example demonstrates how to use the GetFiles method to return file names from a user-specified location.


/*from   w w  w  .  j  a v  a 2 s  .  c  o m*/
using System;
using System.IO;
using System.Collections;

public class RecursiveFileProcessor 
{
    public static void Main(string[] args) 
    {
        string [] fileEntries = Directory.GetFiles("c:/.");
        foreach(string fileName in fileEntries)
           Console.WriteLine(fileName);      
    }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    System.IO »




BinaryReader
BinaryWriter
Directory
DirectoryInfo
DriveInfo
File
FileInfo
FileStream
MemoryStream
Path
StreamReader
StreamWriter
StringReader
StringWriter