C# DirectoryInfo GetFileSystemInfos(String)

Description

DirectoryInfo GetFileSystemInfos(String) Retrieves an array of strongly typed FileSystemInfo objects representing the files and subdirectories that match the specified search criteria.

Syntax

DirectoryInfo.GetFileSystemInfos(String) has the following syntax.


public FileSystemInfo[] GetFileSystemInfos(
  string searchPattern
)

Parameters

DirectoryInfo.GetFileSystemInfos(String) has the following parameters.

  • searchPattern - The search string. For example, "System*" can be used to search for all directories that begin with the word "System".

Returns

DirectoryInfo.GetFileSystemInfos(String) method returns

Example

Retrieves an array of strongly typed FileSystemInfo objects representing the files and subdirectories that match the specified search criteria.


//  ww  w  .  j av a2  s.  c  o  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("*"))
        {
            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