Can I specify a directory path using a template?

I have the following code snippet:

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

It gets files from a specific directory. Can directories be mapped using a template? For example:

 c:\test\di* 

will match all files in directories:

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

I saw that you can pass a file filter to the GetFiles method, but this only applies to files, not directory names.

+8
c # path
source share
1 answer

You have an overload for this, which allows you to specify a search pattern or specify search parameters; another overload :

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

All Articles