gpt4 book ai didi

c# - 可以使用通配符指定目录路径吗?

转载 作者:太空狗 更新时间:2023-10-29 18:27:55 27 4
gpt4 key购买 nike

我有以下代码:

foreach (string file in Directory.GetFiles(sourcePath))
{
// whatever
}

从特定目录获取文件。是否可以使用通配符匹配目录?例如:

c:\test\di*

将匹配目录中的所有文件:

c:\test\dictionary\
c:\test\directory\
c:\test\dig\

我看到您可以将文件过滤器传递给 GetFiles 方法,但这仅适用于文件,不适用于目录名称。

最佳答案

你有一个 overload为此,您可以指定搜索模式,或者如果您需要指定搜索选项,则有 another overload :

foreach (string directory in Directory.GetDirectories(sourcePath, "di*"))
{
// whatever
}

关于c# - 可以使用通配符指定目录路径吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7286477/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com