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,

12
  • Perhaps a permission problem? Commented Aug 9, 2019 at 9:41
  • @Steve no :) i have permissions to access and even i take another folder i have the same error Commented Aug 9, 2019 at 9:44
  • just to be sure try with just @"‪string Folder = C:/Users"; what is the result? Commented Aug 9, 2019 at 9:47
  • What about slashes,C:\Users\... instead of C:/Users/...? Commented Aug 9, 2019 at 9:48
  • 4
    I have copied your path above in Notepad++ and looked at it in Hex format. There are some invisible characters before the C letter. Exactly e2 80 aa Try to rewrite the path directly on your code without copying it from some other source Commented Aug 9, 2019 at 10:45

2 Answers 2

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 
Sign up to request clarification or add additional context in comments.

Comments

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.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.