C# Directory GetDirectoryRoot

Description

Directory GetDirectoryRoot Returns the volume information, root information, or both for the specified path.

Syntax

Directory.GetDirectoryRoot has the following syntax.


public static string GetDirectoryRoot(
  string path
)

Parameters

Directory.GetDirectoryRoot has the following parameters.

  • path - The path of a file or directory.

Returns

Directory.GetDirectoryRoot method returns A string that contains the volume information, root information, or both for the specified path.

Example

The following example illustrates how to set the current directory and display the directory root.


using System;/*  w  w w .ja v  a 2  s.com*/
using System.IO;

public class DirectoryRoot
{
  public static void Main()
  {
    string dir = @"C:\test";    
    Directory.SetCurrentDirectory(dir);
    Console.WriteLine("Root directory: {0}", Directory.GetDirectoryRoot(dir));
  }
}




















Home »
  C# Tutorial »
    System.IO »




BinaryReader
BinaryWriter
Directory
DirectoryInfo
DriveInfo
File
FileInfo
FileStream
MemoryStream
Path
StreamReader
StreamWriter
StringReader
StringWriter