搜索所有文件:拒绝访问 [英] Searching all files: Access Denied
问题描述
大家好,
我正在尝试检索所有文件的列表,但是由于某种原因,它告诉我对某些文件的访问被拒绝,程序结束.
我知道我可以使用catch异常..但是我不想这样做,否则它将忽略那些文件.我需要程序来显示每个文件.
我使用的代码是:
Hi guys,
I am trying to retrieve a list of all files, but for some reason it is telling me access denied on some files and the program ends.
i know i can use a catch exception.. but i dont want to do this, otherwise it ignores those files. I need the program to display EVERY file.
the code i am using is:
// Gets all files in the directory selected and any sub directories
string[] files = Directory.GetFiles(textBoxDirectory.Text, "*", SearchOption.AllDirectories);
它消除了错误:
拒绝访问等等等等"路径.
我试图以管理员身份运行该程序,但仍无法使它正常工作.
有谁对我如何解决这个问题有任何想法?
非常感谢,
Hyps
it kicks back the error:
Access to the path "blah blah blah" is denied.
I have attempted running the program as Administrator and i am still unable to get it to work.
does anyone have any ideas on how i can get around this issue?
Many thanks,
Hyps
推荐答案
检查此链接
http://stackoverflow.com/questions/172544/ignore-文件夹文件何时拒绝目录访问 [ http://stackoverflow.com/questions/4986293/使用目录获取文件时访问路径被拒绝 [
Check this links
http://stackoverflow.com/questions/172544/ignore-folders-files-when-directory-getfiles-is-denied-access[^]
http://stackoverflow.com/questions/4986293/access-to-the-path-is-denied-when-using-directory-getfiles[^]
我想给你一个大的关于System.IO.Directory.GetFiles
的警告.它不像您期望的那样起作用.
请参阅以下讨论: Directory.Get.Files搜索模式问题 [ ^ ].
请注意解决此方法问题的此片段:Where(item => item.ToLower().EndsWith(ExtExe));
—SA
I want to give you a big warning aboutSystem.IO.Directory.GetFiles
. It does not work like you expect it.
See this discussion: Directory.Get.Files search pattern problem[^].
Pay attention to this fragment which fixes the problem of this method:Where(item => item.ToLower().EndsWith(ExtExe));
—SA
这篇关于搜索所有文件:拒绝访问的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!