C# How to know if a given path represents a root drive?

Check if DirectoryInfo.Parent is null or not

DirectoryInfo d = new DirectoryInfo("");
if(d.Parent == null) { IsRoot = true; }

you can also get the root by using DirectoryInfo.Root;


Try this:

if (Path.GetPathRoot(location) == location) {...}

It's much more complicated than checking the Parent property.

Determining Whether a Directory Is a Mounted Folder

One approach would be to see if GetVolumeNameForVolumeMountPoint succeeds.

Of course that won't work for network path, determining if a network drive represents the root directory of a partition may not be possible remotely.