string[] list = Directory.GetFiles("c:\\", "One Two Three - User.xml")
This code does not returns me array, but I have three directories with this file. Any ideas how to m开发者_运维技巧ake it work?
Check out the variation of this method that takes a SearchOption
, here. It seems that you're after a recursive direction search, and the SearchOption enumeration allows you to specify this.
Directory.GetFiles
does not traverse subdirs in this way... so only file on C:\ is returned!!
If you need to search this pattern in a dir and in its subdirs you have to scan (recursively) all subdirs and then current dir. In every step you add files to a global variable (string[] files
).
I think this example can be useful...
Or you can use Directory.GetFiles(path, pattern, SearchOption.AllDirectories);
精彩评论