DirectoryInfo.Root Propiedad

Definición

Obtiene la parte de la raíz del directorio.

C#
public System.IO.DirectoryInfo Root { get; }

Valor de propiedad

Un objeto que representa la raíz del directorio.

Excepciones

El llamador no dispone del permiso requerido.

Ejemplos

En el ejemplo siguiente se muestran las ubicaciones raíz de los directorios especificados.

C#
using System;
using System.IO;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            DirectoryInfo di1 = new DirectoryInfo(@"\\tempshare\tempdir");
            DirectoryInfo di2 = new DirectoryInfo("tempdir");
            DirectoryInfo di3 = new DirectoryInfo(@"x:\tempdir");
            DirectoryInfo di4 = new DirectoryInfo(@"c:\");

            Console.WriteLine("The root path of '{0}' is '{1}'", di1.FullName, di1.Root);
            Console.WriteLine("The root path of '{0}' is '{1}'", di2.FullName, di2.Root);
            Console.WriteLine("The root path of '{0}' is '{1}'", di3.FullName, di3.Root);
            Console.WriteLine("The root path of '{0}' is '{1}'", di4.FullName, di4.Root);
        }
    }
}
/*
This code produces output similar to the following:

The root path of '\\tempshare\tempdir' is '\\tempshare\tempdir'
The root path of 'c:\Projects\ConsoleApplication1\ConsoleApplication1\bin\Debug\tempdir' is 'c:\'
The root path of 'x:\tempdir' is 'x:\'
The root path of 'c:\' is 'c:\'
Press any key to continue . . .

*/

Se aplica a

Producto Versiones
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.3, 1.4, 1.6, 2.0, 2.1
UWP 10.0

Consulte también