有些时候,我们开发的C#应用程序的执行账号,可能没有对一些文件夹和文件的访问权限,当我们使用Directory.Exists和File.Exists方法去判断这些文件夹和文件是否存在的时候,Directory.Exists和File.Exists方法并不会抛出异常报错,这两个方法会返回false,表示查找的文件夹和文件不存在。尽管文件夹和文件实际上是存在的,只是C#程序的执行账号没有权限访问而已,但是Directory.Exists和File.Exists方法还是会返回false,并不会抛出异常报错。

以下是MSDN对Directory.Exists和File.Exists方法的解释,其中也提到了权限不足的问题:

Directory.Exists

Returns
true if path refers to an existing directory; false if the directory does not exist or an error occurs when trying to determine if the specified directory exists.

File.Exists

Returns
true if the caller has the required permissions and path contains the name of an existing file; otherwise, false. This method also returns false if path is null, an invalid path, or a zero-length string. If the caller does not have sufficient permissions to read the specified file, no exception is thrown and the method returns false regardless of the existence of path.

参考链接

Directory.Exists
File.Exists

最新文章

  1. vs2012 发布web应用程序
  2. java 四舍五入保留小数
  3. Javascript——DOM
  4. 剑指offer题目11-20
  5. xcode插件XAlign
  6. 重装yum
  7. do{...}while(0)的作用
  8. Spring 的优秀工具类盘点第 2 部分
  9. Java面试题之数据库三范式是什么
  10. Android开发 第一篇
  11. Beta版本冲刺前准备
  12. 【Win 10 应用开发】UI Composition 札记(三):与 XAML 集成
  13. 离线Chrome插件安装文件(crx)的安装方法
  14. 分析Class类和ClassLoader类下的同名方法getResourceAsStream
  15. 文件进行MD5计算
  16. 一小时上手Java 8新特性
  17. python3+selenium入门09-键盘事件
  18. vue(v-html)和scss的使用问题
  19. 普通用户使用docker命令免sudo权限的问题
  20. Android中fragment之间和Activity的传值、切换

热门文章

  1. ArcGIS地图文档优化 mxdPerfstat工具使用体验
  2. JMeter 检查点之响应断言(Response Assertion)
  3. 贝塞尔曲线UIBezierPath简单使用
  4. screen mac linux下一种让程序后台运行的方法
  5. sql最简单的查询语句
  6. windows server 2008额外域控提升为主域控
  7. 用Python做股市数据分析(一)
  8. mysql启动失败一例
  9. Centos7.5调试/etc/sysctl.conf文件导致宕机
  10. 拓普微智能TFT液晶显示模块