即使目录不存在,Directory Exists方法也返回true [英] Directory Exists method return true even the directory is not present

查看:61
本文介绍了即使目录不存在,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 documentation if there 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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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