Directory.EnumerateFileSystemEntries 方法
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
返回符合指定条件的文件系统条目的可枚举集合。
重载
| 名称 | 说明 |
|---|---|
| EnumerateFileSystemEntries(String) |
返回指定路径中文件名和目录名称的可枚举集合。 |
| EnumerateFileSystemEntries(String, String) |
返回与指定路径中的搜索模式匹配的文件名和目录名称的可枚举集合。 |
| EnumerateFileSystemEntries(String, String, EnumerationOptions) |
返回与指定路径中的搜索模式和枚举选项匹配的文件名和目录名称的可枚举集合。 |
| EnumerateFileSystemEntries(String, String, SearchOption) |
返回与指定路径中的搜索模式匹配的文件名和目录名称的可枚举集合,并选择性地搜索子目录。 |
EnumerateFileSystemEntries(String)
- Source:
- Directory.cs
- Source:
- Directory.cs
- Source:
- Directory.cs
- Source:
- Directory.cs
- Source:
- Directory.cs
返回指定路径中文件名和目录名称的可枚举集合。
public:
static System::Collections::Generic::IEnumerable<System::String ^> ^ EnumerateFileSystemEntries(System::String ^ path);
public static System.Collections.Generic.IEnumerable<string> EnumerateFileSystemEntries(string path);
static member EnumerateFileSystemEntries : string -> seq<string>
Public Shared Function EnumerateFileSystemEntries (path As String) As IEnumerable(Of String)
参数
- path
- String
要搜索的目录的相对路径或绝对路径。 此字符串不区分大小写。
返回
目录中 path文件系统条目的可枚举集合。
例外
.NET Framework 和低于 2.1 的核心版本:.NET path是长度为零的字符串,仅包含空格或包含无效字符。 可以使用该方法 GetInvalidPathChars() 查询无效字符。
path 是 null。
path 无效,例如引用未映射的驱动器。
path 是文件名。
指定的路径、文件名或组合超过了系统定义的最大长度。
调用方没有所需的权限。
调用方没有所需的权限。
注解
可以使用参数指定相对路径信息 path 。 相对路径信息被解释为相对于当前工作目录,可以使用该方法来确定该 GetCurrentDirectory 目录。
方法EnumerateFileSystemEntriesGetFileSystemEntries不同,如下所示:使用EnumerateFileSystemEntries时,可以在返回整个集合之前开始枚举条目的集合;使用GetFileSystemEntries时,必须先等待返回整个条目数组,然后才能访问数组。 因此,处理许多文件和目录时, EnumerateFileSystemEntries 可以更高效。
未缓存返回的集合;每次对集合的 GetEnumerator 调用都将启动一个新的枚举。
适用于
EnumerateFileSystemEntries(String, String)
- Source:
- Directory.cs
- Source:
- Directory.cs
- Source:
- Directory.cs
- Source:
- Directory.cs
- Source:
- Directory.cs
返回与指定路径中的搜索模式匹配的文件名和目录名称的可枚举集合。
public:
static System::Collections::Generic::IEnumerable<System::String ^> ^ EnumerateFileSystemEntries(System::String ^ path, System::String ^ searchPattern);
public static System.Collections.Generic.IEnumerable<string> EnumerateFileSystemEntries(string path, string searchPattern);
static member EnumerateFileSystemEntries : string * string -> seq<string>
Public Shared Function EnumerateFileSystemEntries (path As String, searchPattern As String) As IEnumerable(Of String)
参数
- path
- String
要搜索的目录的相对路径或绝对路径。 此字符串不区分大小写。
- searchPattern
- String
要与文件系统 path条目的名称匹配的搜索字符串。 此参数可以包含有效文本路径和通配符 (* 和 ?) 字符的组合,但它不支持正则表达式。
返回
目录中 path 文件系统条目的可枚举集合,与指定的搜索模式匹配。
例外
.NET Framework 和低于 2.1 的核心版本:.NET path是长度为零的字符串,仅包含空格或包含无效字符。 可以使用该方法 GetInvalidPathChars() 查询无效字符。
-或-
searchPattern 不包含有效的模式。
path 无效,例如引用未映射的驱动器。
path 是文件名。
指定的路径、文件名或组合超过了系统定义的最大长度。
调用方没有所需的权限。
调用方没有所需的权限。
注解
searchPattern 可以是文本字符和通配符的组合,但它不支持正则表达式。 允许在以下通配符说明符中 searchPattern。
| 通配符说明符 | Matches |
|---|---|
| * (星号) | 该位置中的零个或多个字符。 |
| ? (问号) | 该位置正好有一个字符。 |
通配符以外的字符是文本字符。 例如, searchPattern 字符串“*t”搜索以字母“t”结尾的所有名称 path 。
searchPattern字符串“s*”搜索以字母“s”开头的所有名称path。
注释
在“*.txt”等中使用星号通配符 searchPattern 时,指定扩展中的字符数会影响搜索,如下所示:
- 如果指定的扩展名正好是三个字符长,该方法将返回扩展名以指定扩展名开头的文件。 例如,“*.xls”同时返回“book.xls”和“book.xlsx”。
- 在所有其他情况下,该方法返回与指定扩展名完全匹配的文件。 例如,“*.ai”返回“file.ai”,但返回“file.aif”。
使用问号通配符时,此方法仅返回与指定文件扩展名匹配的文件。 例如,给定两个文件“file1.txt”和“file1.txtother”,在目录中,搜索模式为“file?.txt“仅返回第一个文件,而”file*.txt“的搜索模式将返回这两个文件。
searchPattern不能以两个句点(“..”)结尾,或者包含两个句点(“..”)后跟DirectorySeparatorCharAltDirectorySeparatorChar,也不能包含任何无效字符。 可以使用该方法 GetInvalidPathChars 查询无效字符。
可以使用参数指定相对路径信息 path 。 相对路径信息被解释为相对于当前工作目录,可以使用该方法来确定该 GetCurrentDirectory 目录。
方法EnumerateFileSystemEntriesGetFileSystemEntries不同,如下所示:使用EnumerateFileSystemEntries时,可以在返回整个集合之前开始枚举条目的集合;使用GetFileSystemEntries时,必须先等待返回整个条目数组,然后才能访问数组。 因此,处理许多文件和目录时, EnumerateFileSystemEntries 可以更高效。
未缓存返回的集合;每次对集合的 GetEnumerator 调用都将启动一个新的枚举。
适用于
EnumerateFileSystemEntries(String, String, EnumerationOptions)
- Source:
- Directory.cs
- Source:
- Directory.cs
- Source:
- Directory.cs
- Source:
- Directory.cs
- Source:
- Directory.cs
返回与指定路径中的搜索模式和枚举选项匹配的文件名和目录名称的可枚举集合。
public:
static System::Collections::Generic::IEnumerable<System::String ^> ^ EnumerateFileSystemEntries(System::String ^ path, System::String ^ searchPattern, System::IO::EnumerationOptions ^ enumerationOptions);
public static System.Collections.Generic.IEnumerable<string> EnumerateFileSystemEntries(string path, string searchPattern, System.IO.EnumerationOptions enumerationOptions);
static member EnumerateFileSystemEntries : string * string * System.IO.EnumerationOptions -> seq<string>
Public Shared Function EnumerateFileSystemEntries (path As String, searchPattern As String, enumerationOptions As EnumerationOptions) As IEnumerable(Of String)
参数
- path
- String
要搜索的目录的相对路径或绝对路径。 此字符串不区分大小写。
- searchPattern
- String
要与中 path文件和目录的名称匹配的搜索字符串。 此参数可以包含有效文本和通配符的组合,但它不支持正则表达式。
- enumerationOptions
- EnumerationOptions
描述要使用的搜索和枚举配置的对象。
返回
与指定的搜索模式和指定的枚举选项匹配的目录中 path文件系统条目的可枚举集合。
例外
.NET Framework 和低于 2.1 的核心版本:.NET path是长度为零的字符串,仅包含空格或包含无效字符。 可以使用该方法 GetInvalidPathChars() 查询无效字符。
-或-
searchPattern 不包含有效的模式。
path 无效,例如引用未映射的驱动器。
path 是文件名。
指定的路径、文件名或组合超过了系统定义的最大长度。
调用方没有所需的权限。
调用方没有所需的权限。
注解
searchPattern 可以是文本字符和通配符的组合,但它不支持正则表达式。 允许在以下通配符说明符中 searchPattern。
| 通配符说明符 | Matches |
|---|---|
| * (星号) | 该位置中的零个或多个字符。 |
| ? (问号) | 该位置正好有一个字符。 |
通配符以外的字符是文本字符。 例如, searchPattern 字符串“*t”搜索以字母“t”结尾的所有名称 path 。
searchPattern字符串“s*”搜索以字母“s”开头的所有名称path。
注释
在“*.txt”等中使用星号通配符 searchPattern 时,指定扩展中的字符数会影响搜索,如下所示:
- 如果指定的扩展名正好是三个字符长,该方法将返回扩展名以指定扩展名开头的文件。 例如,“*.xls”同时返回“book.xls”和“book.xlsx”。
- 在所有其他情况下,该方法返回与指定扩展名完全匹配的文件。 例如,“*.ai”返回“file.ai”,但返回“file.aif”。
使用问号通配符时,此方法仅返回与指定文件扩展名匹配的文件。 例如,给定两个文件“file1.txt”和“file1.txtother”,在目录中,搜索模式为“file?.txt“仅返回第一个文件,而”file*.txt“的搜索模式将返回这两个文件。
searchPattern不能以两个句点(“..”)结尾,或者包含两个句点(“..”)后跟DirectorySeparatorCharAltDirectorySeparatorChar,也不能包含任何无效字符。 可以使用该方法 GetInvalidPathChars 查询无效字符。
可以使用参数指定相对路径信息 path 。 相对路径信息被解释为相对于当前工作目录,可以使用该方法来确定该 GetCurrentDirectory 目录。
方法EnumerateFileSystemEntriesGetFileSystemEntries不同,如下所示:使用EnumerateFileSystemEntries时,可以在返回整个集合之前开始枚举条目的集合;使用GetFileSystemEntries时,必须先等待返回整个条目数组,然后才能访问数组。 因此,处理许多文件和目录时, EnumerateFileSystemEntries 可以更高效。
未缓存返回的集合;每次对集合的 GetEnumerator 调用都将启动一个新的枚举。
适用于
EnumerateFileSystemEntries(String, String, SearchOption)
- Source:
- Directory.cs
- Source:
- Directory.cs
- Source:
- Directory.cs
- Source:
- Directory.cs
- Source:
- Directory.cs
返回与指定路径中的搜索模式匹配的文件名和目录名称的可枚举集合,并选择性地搜索子目录。
public:
static System::Collections::Generic::IEnumerable<System::String ^> ^ EnumerateFileSystemEntries(System::String ^ path, System::String ^ searchPattern, System::IO::SearchOption searchOption);
public static System.Collections.Generic.IEnumerable<string> EnumerateFileSystemEntries(string path, string searchPattern, System.IO.SearchOption searchOption);
static member EnumerateFileSystemEntries : string * string * System.IO.SearchOption -> seq<string>
Public Shared Function EnumerateFileSystemEntries (path As String, searchPattern As String, searchOption As SearchOption) As IEnumerable(Of String)
参数
- path
- String
要搜索的目录的相对路径或绝对路径。 此字符串不区分大小写。
- searchPattern
- String
要与文件系统条目匹配的 path搜索字符串。 此参数可以包含有效文本路径和通配符 (* 和 ?) 字符的组合,但它不支持正则表达式。
- searchOption
- SearchOption
枚举值之一,指定搜索操作是否应仅包括当前目录,还是应包含所有子目录。 默认值为 TopDirectoryOnly。
返回
目录中 path 文件系统条目的可枚举集合,与指定的搜索模式和选项匹配。
例外
.NET Framework 和低于 2.1 的核心版本:.NET path是长度为零的字符串,仅包含空格或包含无效字符。 可以使用该方法 GetInvalidPathChars() 查询无效字符。
-或-
searchPattern 不包含有效的模式。
searchOption 不是有效 SearchOption 值。
path 无效,例如引用未映射的驱动器。
path 是文件名。
指定的路径、文件名或组合超过了系统定义的最大长度。
调用方没有所需的权限。
调用方没有所需的权限。
注解
searchPattern 可以是文本字符和通配符的组合,但它不支持正则表达式。 允许在以下通配符说明符中 searchPattern。
| 通配符说明符 | Matches |
|---|---|
| * (星号) | 该位置中的零个或多个字符。 |
| ? (问号) | 该位置正好有一个字符。 |
通配符以外的字符是文本字符。 例如, searchPattern 字符串“*t”搜索以字母“t”结尾的所有名称 path 。
searchPattern字符串“s*”搜索以字母“s”开头的所有名称path。
注释
在“*.txt”等中使用星号通配符 searchPattern 时,指定扩展中的字符数会影响搜索,如下所示:
- 如果指定的扩展名正好是三个字符长,该方法将返回扩展名以指定扩展名开头的文件。 例如,“*.xls”同时返回“book.xls”和“book.xlsx”。
- 在所有其他情况下,该方法返回与指定扩展名完全匹配的文件。 例如,“*.ai”返回“file.ai”,但返回“file.aif”。
使用问号通配符时,此方法仅返回与指定文件扩展名匹配的文件。 例如,给定两个文件“file1.txt”和“file1.txtother”,在目录中,搜索模式为“file?.txt“仅返回第一个文件,而”file*.txt“的搜索模式将返回这两个文件。
searchPattern不能以两个句点(“..”)结尾,或者包含两个句点(“..”)后跟DirectorySeparatorCharAltDirectorySeparatorChar,也不能包含任何无效字符。 可以使用该方法 GetInvalidPathChars 查询无效字符。
可以使用参数指定相对路径信息 path 。 相对路径信息被解释为相对于当前工作目录,可以使用该方法来确定该 GetCurrentDirectory 目录。
方法EnumerateFileSystemEntriesGetFileSystemEntries不同,如下所示:使用EnumerateFileSystemEntries时,可以在返回整个集合之前开始枚举条目的集合;使用GetFileSystemEntries时,必须先等待返回整个条目数组,然后才能访问数组。 因此,处理许多文件和目录时, EnumerateFileSystemEntries 可以更高效。
未缓存返回的集合;每次对集合的 GetEnumerator 调用都将启动一个新的枚举。