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

asmo picture asmo · Feb 19, 2011 · Viewed 18.7k times · Source

How can I know if a given directory is a root drive?

(aside from checking if its path equals to "A:", "B:", "C:", etc.)

Answer

Dustin Davis picture Dustin Davis · Feb 19, 2011

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;