dr.Crow
dr.Crow

Reputation: 1563

check if url unc directory path exist

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).

Upvotes: 1

Views: 1972

Answers (1)

TechnicalTophat
TechnicalTophat

Reputation: 1725

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

Upvotes: 3

Related Questions