【问题标题】:Message if Path dont exists in C#?如果路径在 C# 中不存在,则消息?
【发布时间】:2015-02-19 14:48:53
【问题描述】:

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

        if (Directory.Exists(path))
            MessageBox.Show("FAIL");
        {

            else if  ;Process.Start(path);

【问题讨论】:

  • 请准确发布您尝试过但不起作用的内容。
  • 我猜你还没有完成作业..
  • 现在添加了你能帮我吗
  • 请返回并编辑该示例代码 - 您发布的内容是垃圾,无法编译。

标签: c# visual-studio-2010 path


【解决方案1】:
if (Directory.Exists(path))
{
    Process.Start(path);
}
else
{
    MessageBox.Show("Fail");
}

【讨论】:

  • 那么你的'path'字符串肯定有问题。
  • @HassanBrate 不要只说“不起作用”。这就像对医生说“很痛”,然后一言不发。错误是什么?会发生什么?
  • @user3684526 Directory.Exists 不会告诉你 file 是否存在。
  • Directory.Exists 告诉您是否存在目录,您需要使用 File.Exists 因此代码中的文字。
【解决方案2】:
if (!File.Exist(path to file))
 {
   MessageBox.Show("File Not Found");
 }
 else
  //process code here

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-08-10
    • 2015-09-03
    • 1970-01-01
    • 2022-11-27
    • 2017-10-25
    • 1970-01-01
    • 2018-08-21
    • 2019-02-17
    相关资源
    最近更新 更多