需要在C#中读取目录 [英] Need to read directories in C#

查看:72
本文介绍了需要在C#中读取目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

错误:

Error:

Access to the path 'C:\Users\.NET v2.0' is denied.





我尝试过:





What I have tried:

String[] allfiles = null;
allfiles = System.IO.Directory.GetFiles("C://Users", "*.*", System.IO.SearchOption.AllDirectories);

推荐答案

这很容易

Easy as this
string[] folders = System.IO.Directory.GetDirectories(@"C:\My Sample Path\","*", System.IO.SearchOption.AllDirectories);



如果您收到拒绝访问消息,请以管理员身份运行Visual Studio。



谢谢&注意

SHAM:)


If you get Access denied message, run your visual studio as administrator.

Thanks & Regard
SHAM :)


你好


你必须提供你所在文件夹的完整路径查看文件。



Hi
you have to provide the full path for the folder from where you are looking the files.

String[] allfiles = null;
            allfiles = System.IO.Directory.GetFiles("C://Users/.NET v2.0", "*.*", System.IO.SearchOption.AllDirectories);







在用户文件夹中,您无法访问的文件夹很少,这就是您的原因收到此错误或您可以以管理员身份运行VS.




As in users folder there are few folder on which you don't have access, that's why you are getting this error or you can run your VS as administrator.


这篇关于需要在C#中读取目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆