1

我想我发现了一个错误。在我看来 Process.Start 运行错误的目录。要进行测试,请创建默认控制台应用程序模板并粘贴以下内容:


using System;
using System.Diagnostics;
using System.IO;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            bool test = false;

            DirectoryInfo root = Directory.CreateDirectory(
                System.IO.Path.Combine(Directory.GetCurrentDirectory(), "folder"));

            DirectoryInfo bug = Directory.CreateDirectory(
                System.IO.Path.Combine(root.FullName, "bug"));
            DirectoryInfo bugDotCom = Directory.CreateDirectory(
                System.IO.Path.Combine(root.FullName, "bug.com"));

            ProcessStartInfo bugPSI = new ProcessStartInfo(bug.FullName);
            ProcessStartInfo bugDotComPSI = new ProcessStartInfo(bugDotCom.FullName);

            if (test)
            {
                Console.WriteLine(bug.FullName);
                Process.Start(bugPSI);
            }
            else
            {
                Console.WriteLine(bugDotCom.FullName);
                Process.Start(bugDotComPSI);
            }
            Console.ReadKey();
        }
    }
}

当变量test设置为 false 时,应该打开bug.com目录,否则打开bug目录。但是,此示例显示始终打开bug.com(无论测试变量) - 至少对我而言。怎么了?我错过了什么或者这只是一个错误?

4

1 回答 1

2

.com是 的一部分%PATHEXT%,因此如果存在,Windows 将使用它。

更改扩展名以便没有bug.com文件夹可以避免该问题。

要解决此问题,请将 a 添加\到路径的末尾。

于 2011-04-03T23:58:07.383 回答