Alex Rivera | Logout

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

Asked 2011-02-18T23:14:35.870
39

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

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

Edit
Report

1 Answer

39

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;

answered 2011-02-18T23:16:55.537

Your Answer