如果 C# 中不存在路径,则显示消息



有没有办法检查路径是否存在,如果没有,则显示路径不存在的消息存在于 C# 中?我已经尝试了if和else方法,但不起作用,顺便说一句,在询问之前,我真的在Google上搜索了:P

        if (Directory.Exists(path))
            MessageBox.Show("FAIL");
        {
            else if  ;Process.Start(path);
if (!File.Exist(path to file))
 {
   MessageBox.Show("File Not Found");
 }
 else
  //process code here

还需要添加使用 System.IO 命名空间

if (Directory.Exists(path))
{
    Process.Start(path);
}
else
{
    MessageBox.Show("Fail");
}