1

I am trying to check if the unc path folder (from web user input) was existing, here's my code:

Directory.Exists("file://localhost/c$/folderName/"); //this always return false

This is not duplicate of : how-to-quickly-check-if-unc-path-is-available since I was dealing with url unc path (using "//" backslash).

Community
  • 1
  • 1
dr.Crow
  • 1,493
  • 14
  • 17

1 Answers1

3

You need to use the URI type. First, define a new URI using your UNC path

Uri foo = new Uri("file://localhost/c$/folderName/");

Then you need to just test it using

Directory.Exists(foo.LocalPath);.

This returns a boolean and will allow you to execute code based on the value.

So your whole code would be like below:

Uri foo = new Uri("file://localhost/c$/folderName/");

if (!Directory.Exists(foo.LocalPath))
{
  Debug.Log("UNC does not exist or is not accessible!");
}
else
{
  Debug.Log("UNC exists!");
}
TechnicalTophat
  • 1,655
  • 1
  • 15
  • 37