Is there a quick way to check whether a path I have is on a local disk or somewhere on the network? I can't just check to see if it's a drive letter vs. UNC, because that would incorrectly identify mapped drives as local. I assumed it would be a boolean in the DirectoryInfo object, but it appears that it's not.
I've found classic VB code to do this check (through an API), but nothing for .NET so far.
System.IO.DirectoryInfo di;
if (System.IO.Path.IsPathRooted(di.FullName))
{
System.IO.DriveInfo drive = new System.IO.DriveInfo(System.IO.Path.GetPathRoot(di.FullName));
if (drive.DriveType == System.IO.DriveType.Network)
{
// do something
}
}
else // shouldn't be reached
{
// relative path => local
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With