开发者

Directory.GetFiles does not work as expected

开发者 https://www.devze.com 2023-03-02 23:24 出处:网络
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
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);

0

精彩评论

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