Is their any way to find root directory without knowing the full path.
For example, I'm having Folder\subfolder
I want to find the root directory like c:\, d:\, e:\
in which that subfolder
presents
I had tried by using DirectoryInfo("path").Root.Name
, Path.GetPathRoot(path)
but it doesn't works.
You first need to the full path and then the root of it:
string path = ...
string root = Directory.GetDirectoryRoot(Path.GetFullPath(path));
Try:
string result = Path.GetPathRoot(Path.GetFullPath("MyPath"));
This uses the current working directory (which is the only way that you can convert a relative path to a full path - the relative path is always relative to the current working directory).
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