C# DirectoryInfo GetFileSystemInfos(String, SearchOption)

Description

DirectoryInfo GetFileSystemInfos(String, SearchOption) Retrieves an array of FileSystemInfo objects that represent the files and subdirectories matching the specified search criteria.

Syntax

DirectoryInfo.GetFileSystemInfos(String, SearchOption) has the following syntax.


public FileSystemInfo[] GetFileSystemInfos(
  string searchPattern,
  SearchOption searchOption
)

Parameters

DirectoryInfo.GetFileSystemInfos(String, SearchOption) has the following parameters.

  • searchPattern - The search string. The default pattern is "*", which returns all files and directories.
  • searchOption - One of the enumeration values that specifies whether the search operation should include only the current directory or all subdirectories. The default value is TopDirectoryOnly.

Returns

DirectoryInfo.GetFileSystemInfos(String, SearchOption) method returns

Example

Retrieves an array of FileSystemInfo objects that represent the files and subdirectories matching the specified search criteria.


//  w  ww.  jav  a2s. co m
using System;
using System.IO;

class Program
{
    static void Main(string[] args)
    {
        DirectoryInfo di = new DirectoryInfo(@"C:\Users\");
        foreach (var fi in di.GetFileSystemInfos("*",SearchOption.AllDirectories))
        {
            Console.WriteLine(fi.Name);
        }

    }
}

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