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 files 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
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With