程序说已经制作了一个新目录,但在目标文件夹中不可见

发布于 2025-01-21 12:31:26 字数 880 浏览 0 评论 0原文

我制作了一个简单的C#程序,该程序采用了目录的路径,如果该目录不存在,它将在给定的路径中创建它,但是当我转到应该创建它的路径时,没有显示目录。

using System;
using System.IO;

namespace Test
{

    class Program
    {
        static void Main(string[] args)
        {
            DirectoryInfo DIR = new DirectoryInfo(@"E:\A\B");

            try
            {
                if(DIR.Exists)
                {
                    Console.WriteLine("This folder already exists!");
                }
                else
                {
                    DIR.Create();
                    Console.WriteLine("Folder created!");
                }
            }
            catch(Exception ex)
            {
                Console.ForegroundColor = System.ConsoleColor.Red;
                Console.WriteLine("Folder counldnt be created due to " + ex);
            }
        }
    }
}

I made a simple c# program that takes a path of a directory, and if that directory doesn't exist, it creates it in the given path, but when I go to the path where it should have been created, no directory is shown.

using System;
using System.IO;

namespace Test
{

    class Program
    {
        static void Main(string[] args)
        {
            DirectoryInfo DIR = new DirectoryInfo(@"E:\A\B");

            try
            {
                if(DIR.Exists)
                {
                    Console.WriteLine("This folder already exists!");
                }
                else
                {
                    DIR.Create();
                    Console.WriteLine("Folder created!");
                }
            }
            catch(Exception ex)
            {
                Console.ForegroundColor = System.ConsoleColor.Red;
                Console.WriteLine("Folder counldnt be created due to " + ex);
            }
        }
    }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

终止放荡 2025-01-28 12:31:26

如果您的程序在第二次运行中告诉您,该文件夹已经存在,我认为您正在寻找错误的位置。您是否有多台计算机,或者这是在虚拟机中运行的,并且正在检查主机?还是只是您的探险家不刷新?

我刚刚添加了一行system.diagnostics.process.start(dir.fullname); 在启动资源管理器并打开新创建的目录的程序中。

如果那将失败,那么您应该将您的E:驱动器chkdsk chkdsk,也许有些东西破了。

using System;
using System.IO;

namespace Test
{
  internal class Program
  {
    static void Main (string[] args)
    {
      DirectoryInfo DIR = new DirectoryInfo (@"E:\A\B");

      try
      {
        if (DIR.Exists)
        {
          Console.WriteLine ("This folder already exists!");
        }
        else
        {
          DIR.Create ();
          Console.WriteLine ("Folder created!");
          System.Diagnostics.Process.Start (DIR.FullName);
        }
      }
      catch (Exception ex)
      {
        Console.ForegroundColor = System.ConsoleColor.Red;
        Console.WriteLine ("Folder counldnt be created due to " + ex);
      }

      Console.ReadKey ();
    }
  }
}

If your program tells you on the second run that the folder already exists I assume you are looking in the wrong place. Do you have multiple computers or is this running in a virtual machine and you are checking on the host? Or is just your explorer not refreshing?

I just added one line System.Diagnostics.Process.Start (DIR.FullName); to your program that starts the explorer and opens the newly created directory.

If even that will fail you should chkdsk your E: drive, perhaps there is something broken.

using System;
using System.IO;

namespace Test
{
  internal class Program
  {
    static void Main (string[] args)
    {
      DirectoryInfo DIR = new DirectoryInfo (@"E:\A\B");

      try
      {
        if (DIR.Exists)
        {
          Console.WriteLine ("This folder already exists!");
        }
        else
        {
          DIR.Create ();
          Console.WriteLine ("Folder created!");
          System.Diagnostics.Process.Start (DIR.FullName);
        }
      }
      catch (Exception ex)
      {
        Console.ForegroundColor = System.ConsoleColor.Red;
        Console.WriteLine ("Folder counldnt be created due to " + ex);
      }

      Console.ReadKey ();
    }
  }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文