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 (see Remarks), but doesn't support regular expressions.
- searchOption
- One of the enumeration values that specifies whether the search operation should include only the current directory or should include all subdirectories. The default value is System.IO.SearchOption.TopDirectoryOnly.
Return Value
An enumerable collection of the full names (including paths) for the files in the directory specified by path and that match the specified search pattern and option.Exception | Description |
---|---|
System.ArgumentException | %path %is a zero-length string, contains only white space, or contains invalid characters. You can query for invalid characters by using the System.IO.Path.GetInvalidPathChars method.- or -searchPattern does not contain a valid pattern. |
System.ArgumentNullException | path is null.-or-searchPattern is null. |
System.ArgumentOutOfRangeException | searchOption is not a valid System.IO.SearchOption value. |
System.IO.DirectoryNotFoundException | path is invalid, such as referring to an unmapped drive. |
System.IO.IOException | path is a file name. |
System.IO.PathTooLongException | The specified path, file name, or combined exceed the system-defined maximum length. For example, on Windows-based platforms, paths must be less than 248 characters and file names must be less than 260 characters. |
System.Security.SecurityException | The caller does not have the required permission. |
System.UnauthorizedAccessException | The caller does not have the required permission. |
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