Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.
0 out of 2 rated this helpful - Rate this topic

DirectoryInfo.Root Property

Gets the root portion of a path.

Namespace: System.IO
Assembly: mscorlib (in mscorlib.dll)

public DirectoryInfo Root { get; }
/** @property */
public DirectoryInfo get_Root ()

public function get Root () : DirectoryInfo

Property Value

A DirectoryInfo object representing the root of a path.
Exception typeCondition

SecurityException

The caller does not have the required permission.

The following table lists examples of other typical or related I/O tasks.

To do this...

See the example in this topic...

Retrieve the fully qualified path of a file.

Path.GetFullPath

Retrieve only the directory name from a path.

Path.GetDirectoryName

See the files in a directory.

Name

See the subdirectories of a directory.

Directory.GetDirectories

DirectoryInfo.GetDirectories

See all the files and all the subdirectories in a directory.

GetFileSystemInfos

Find the size of a directory.

Directory

Rename or move a directory.

Directory.Move

DirectoryInfo.MoveTo

Determine if a file exists.

Exists

Determine if a directory exists.

Exists

The following example demonstrates how to determine the root location of a specified directory.

using System;
using System.IO;

public class MoveToTest 
{
    public static void Main() 
    {

        // Make a reference to a directory.
        DirectoryInfo di = new DirectoryInfo("TempDir");

        // Create the directory only if it does not already exist.
        if (di.Exists == false)
            di.Create();

        // Create a subdirectory in the directory just created.
        DirectoryInfo dis = di.CreateSubdirectory("SubDir");
        Console.WriteLine("The root path of '{0}' is '{1}'", dis.Name, dis.Root);

        // Delete the parent directory.
        di.Delete(true);
    }
}

import System.*;
import System.IO.*;

public class MoveToTest
{
    public static void main(String[] args)
    {
        // Make a reference to a directory.
        DirectoryInfo di = new DirectoryInfo("TempDir");

        // Create the directory only if it does not already exist.
        if (di.get_Exists() == false) {
            di.Create();
        }

        // Create a subdirectory in the directory just created.
        DirectoryInfo dis = di.CreateSubdirectory("SubDir");

        Console.WriteLine("The root path of '{0}' is '{1}'", 
            dis.get_Name(), dis.get_Root());

        // Delete the parent directory.
        di.Delete(true);
    } //main
} //MoveToTest

import System;
import System.IO;

public class MoveToTest {
    public static function Main() {

        // Make a reference to a directory.
        var di : DirectoryInfo = new DirectoryInfo("TempDir");

        // Create the directory only if it does not already exist.
        if (di.Exists == false)
            di.Create();

        // Create a subdirectory in the directory just created.
        var dis : DirectoryInfo = di.CreateSubdirectory("SubDir");

        Console.WriteLine("The root path of '{0}' is '{1}'", dis.Name, dis.Root);

        // Delete the parent directory.
        di.Delete(true);
    }
}
MoveToTest.Main();

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0, 1.0
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

Show:
© 2014 Microsoft. All rights reserved.