1

I have a console App (dotnet core)

        Console.WriteLine("Hello World!");
        string Folder = @"‪C:/Users/Admin/Desktop/local-folder";
        DirectoryInfo d = new DirectoryInfo(Folder);
        bool isExist = Directory.Exists(Folder);
        bool isExist2 = d.Exists;

The issue is that isExist and isExist2 take always false even the folder exists !

It seems that , each time, the folder path is considered as a relative path.

So how can I fix this?

Thanks,

Lamloumi Afif
  • 8,941
  • 26
  • 98
  • 191

2 Answers2

1

You need to specify the path following way:

string Folder = @"‪C:\\Users\Admin\Desktop\local-folder"

The following outputs true for me in .net core 2.2 application:

string Folder = @"C:\\Users\ehsan.sajjad\Source\Repos\order-processor\Src";
System.IO.DirectoryInfo d = new System.IO.DirectoryInfo(Folder);
bool isExist = System.IO.Directory.Exists(Folder); // true
Ehsan Sajjad
  • 61,834
  • 16
  • 105
  • 160
1

Your code seems to be working fine. The only problem there is your path.If you have copied it then Try rewriting the path on your own. As mentioned by @steve there are some invisible characters in your path.

Workaholic
  • 93
  • 12