我正在尝试编写一个函数来确定文件是否存在。事实证明,这两种方法返回不一致的结果(与返回误报的 isFileFound() 相比,fileExists() 似乎提供了准确的结果 - 我在尝试创建实例时预计会出现异常)。
protected bool isFileFound(string path, string fileName)
{
System.IO.FileInfo fi = null;
bool found = false;
try
{
fi = new System.IO.FileInfo(path + fileName);
found = true;
}
catch (Exception e)
{
baselogger.Fatal(e.Message + " " + e.StackTrace + " \n" + path + fileName);
}
return found;
}
protected bool fileExists(string path, string pattern)
{
bool success = false;
try
{
success = File.Exists(path + pattern);
}
catch (Exception e)
{
baselogger.Warn(e.Message + " " + e.StackTrace + " " + e.Source);
}
return success;
}
似乎都无法解析以下语法的 UNC 路径:\abcserve