'Program says that a new directory has been made, but its not visible in destination folder

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);
            }
        }
    }
}


Solution 1:[1]

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 ();
    }
  }
}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Johannes Krackowizer