C#
Parameters
- path
- The relative or absolute path to the directory to search. This string is not case-sensitive.
- searchPattern
- The search string to match against the names of files in path. This parameter can contain a combination of valid literal path and wildcard (* and ?) characters, but doesn't support regular expressions.
Return Value
An array of the full-path file names in the specified directory that match the specified search pattern or an empty array if no files found.Exception | Description |
---|---|
System.IO.IOException | path is a file name. -or- A network error has occurred. |
System.UnauthorizedAccessException | The caller does not have the required permission. |
System.ArgumentException | path is a zero-length string, contains only white space, or contains one or more invalid characters. -or- searchPattern does not contain a valid pattern. |
System.ArgumentNullException | path or searchPattern
is null . |
System.IO.DirectoryNotFoundException | The specified path is not found or invalid (for example, it is on an unmapped drive). |
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 searchPattern string "*t" searches for all names in path ending with the letter "t". The searchPattern string "s*" searches for all names in path beginning with the letter "s". searchPattern cannot end in two periods ("..") or contain two periods ("..") followed by '/' or '\', nor can it contain any invalid characters.
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2