即使目录不存在,Directory Exists方法也返回true

编程入门 行业动态 更新时间:2024-10-27 12:28:53
本文介绍了即使目录不存在,Directory Exists方法也返回true的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

Hello All,

Hello All,

Directory.Exists(Path.GetDirectoryName( FilePath);

Directory.Exists(Path.GetDirectoryName(FilePath);

即使目录不存在,它也会返回true。

It returns true even if the directory is not present.

任何想法?

推荐答案

尝试编写简单的控制台程序并将您输入的路径提供给Path.GetDirectoryName(),您将看到。它由 文档如果在提供的参数中没有"路径"组件(即:由"\\"或"/"组成的字符串),它将返回String.Empty ,它被视为当前目录。

Try write simple console program and feed the path you entered to Path.GetDirectoryName() and you'll see.It is spelt out by the documentationifthere aren't "path" component in the parameter supplied (i.e.: strings separated by "\\" or "/"),it'll return String.Empty, which is treated as the current directory.

要测试FilePath是否存在,只需将路径放到Directory.Exists()。

To test whether FilePath exists, just put the path to Directory.Exists().

更多推荐

即使目录不存在,Directory Exists方法也返回true

本文发布于:2023-06-08 14:28:52,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/583078.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:不存在   目录   方法   Directory   Exists

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!