开发者

Possible to specify directory path with a wildcard?

I have the following piece of code:

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

That gets files from a specific directory. Would it be possible to match directories using a wildcard? For example:

c:\test\di*

would match all files in the directories:

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

I saw that you can pass a file filter to the GetFiles method, but that applies to fi开发者_如何学Goles only, not directory names.


You have an overload for this which allows you to specify a search pattern or if you need to specify search options there's another overload:

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜