System.IO.File.Exist始终返回true [英] System.IO.File.Exist returns always true
本文介绍了System.IO.File.Exist始终返回true的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在我的程序中,使用System.IO.Exists(strFile)检查文件是否存在。
In my program, check whether file exists or not using System.IO.Exists(strFile).
但是如果strFile = @" \则返回true test.cfg"
However returns true in case of strFile = @"\test.cfg"
有人可以给我任何想法吗?
Can anybody give me any idea about this?
推荐答案
您好,
我假设您的意思是System.IO.File.Exists。
I assume you mean System.IO.File.Exists.
如果我此时运行此代码,则没有该文件我期望(并且做)点击其他。
If I run this code at this time don't have that file I expected (and do) hit the else.
var fileName = @"\test.cfg";
if (File.Exists(fileName))
{
Console.WriteLine("Exists");
}
else
{
Console.WriteLine("No exists");
}
也许您可以添加更多详细信息,例如路径在哪里?在网络或本地机器上等。
Perhaps you can add more details like where is the path e.g. on a network or local machine etc.
这篇关于System.IO.File.Exist始终返回true的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文