System.IO.DirectoryInfo.GetFileSystemInfos Method

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

Syntax

public FileSystemInfo[] GetFileSystemInfos (string searchPattern)

Parameters

searchPattern
The search string to match against the names of directories and files. This parameter can contain a combination of valid literal path and wildcard (* and ?) characters (see Remarks), but doesn't support regular expressions. The default pattern is "*", which returns all files.

Returns

An array of strongly typed FileSystemInfo objects matching the search criteria.

Remarks

searchPattern can be a combination of literal and wildcard characters, but doesn't support regular expressions. The following wildcard specifiers are permitted in searchPattern.

* (asterisk)

Zero or more characters in that position.

? (question mark)

Zero or one character in that position.

Characters other than the wildcard are literal characters. For example, the string "*t" searches for all names in ending with the letter "t". ". The searchPattern string "s*" searches for all names in path beginning with the letter "s".

This method is not recursive.

For subdirectories, the System.IO.FileSystemInfo objects returned by this method can be cast to the derived class System.IO.DirectoryInfo. Use the System.IO.FileAttributes value returned by the FileSystemInfo.Attributes property to determine whether the System.IO.FileSystemInfo represents a file or a directory.

Wild cards are permitted. For example, the searchPattern string "*t" searches for all directory names in path ending with the letter "t". The searchPattern string "s*" searches for all directory names in path beginning with the letter "s".

The string ".." can only be used in searchPattern if it is specified as a part of a valid directory name, such as in the directory name "a..b". It cannot be used to move up the directory hierarchy. If there are no files or directories, or no files or directories that match the searchPattern string in the System.IO.DirectoryInfo, this method returns an empty array.

This method pre-populates the values of the following System.IO.FileSystemInfo properties:

Requirements

Namespace: System.IO
Assembly: mscorlib (in mscorlib.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0, 4.0.0.0