Name
Directory.GetDirectoryRoot Method
Class
System.IO.Directory
Syntax
Directory.GetDirectoryRoot(path)-
path Use: Required
Data Type: String
A valid path to a directory
Return Value
A String containing the name of the root directory of
path
Description
Returns the name of the root directory of the drive on which
path resides (assuming that
path is valid). For example, the code:
Directory.GetDirectoryRoot("c:\program files\accessories")returns the string C:\ as the root directory.
Rules at a Glance
pathcan be either an absolute path (a complete path from the root directory to the target directory) or a relative path (starting from the current directory to the target directory).pathcan be either a path on the local system, the path of a mapped network drive, or a UNC path. For example, the code:Directory.GetDirectoryRoot("\\Pentium\C\AFolder")returns
\\Pentium\C, and if the folder\\Pentium\C\AFoldermaps to the network drive Z, then:Directory.GetDirectoryRoot("Z:\temp")returns
Z:\.pathcannot contain wildcard characters.
See Also
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access