DirectoryInfo.Root Propriedade
Definição
Importante
Algumas informações se referem a produtos de pré-lançamento que podem ser substancialmente modificados antes do lançamento. A Microsoft não oferece garantias, expressas ou implícitas, das informações aqui fornecidas.
Obtém a parte da raiz do diretório.
public:
property System::IO::DirectoryInfo ^ Root { System::IO::DirectoryInfo ^ get(); };
public System.IO.DirectoryInfo Root { get; }
member this.Root : System.IO.DirectoryInfo
Public ReadOnly Property Root As DirectoryInfo
Valor da propriedade
Um objeto que representa a raiz do diretório.
Exceções
O chamador não tem a permissão necessária.
Exemplos
O exemplo a seguir exibe locais raiz para diretórios especificados.
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 . . .
*/
open System.IO
let di1 = DirectoryInfo @"\\tempshare\tempdir"
let di2 = DirectoryInfo "tempdir"
let di3 = DirectoryInfo @"x:\tempdir"
let di4 = DirectoryInfo @"c:\"
printfn $"The root path of '{di1.FullName}' is '{di1.Root}'"
printfn $"The root path of '{di2.FullName}' is '{di2.Root}'"
printfn $"The root path of '{di3.FullName}' is '{di3.Root}'"
printfn $"The root path of '{di4.FullName}' is '{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 . . .
*)
Imports System.IO
Module Module1
Sub Main()
Dim di1 As DirectoryInfo = New DirectoryInfo("\\tempshare\tempdir")
Dim di2 As DirectoryInfo = New DirectoryInfo("tempdir")
Dim di3 As DirectoryInfo = New DirectoryInfo("x:\tempdir")
Dim di4 As DirectoryInfo = 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)
End Sub
End Module
' 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 . . .
Aplica-se a
Confira também
Colabore connosco no GitHub
A origem deste conteúdo pode ser encontrada no GitHub, onde também pode criar e rever problemas e pedidos Pull. Para mais informações, consulte o nosso guia do contribuidor.