DirectoryInfo.Name Property
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Gets the name of this DirectoryInfo instance.
public:
virtual property System::String ^ Name { System::String ^ get(); };
public override string Name { get; }
member this.Name : string
Public Overrides ReadOnly Property Name As String
The directory name.
The following example displays the name of the current DirectoryInfo
instance only.
using namespace System;
using namespace System::IO;
int main()
{
DirectoryInfo^ dir = gcnew DirectoryInfo( "." );
String^ dirName = dir->Name;
Console::WriteLine( "DirectoryInfo name is {0}.", dirName );
}
using System;
using System.IO;
class GetAName
{
public static void Main(string[] args)
{
DirectoryInfo dir = new DirectoryInfo(".");
string dirName=dir.Name;
Console.WriteLine("DirectoryInfo name is {0}.", dirName);
}
}
open System.IO
let dir = DirectoryInfo "."
let dirName = dir.Name
printfn $"DirectoryInfo name is {dirName}."
Imports System.IO
Class GetAName
Public Shared Sub Main()
Dim dir As New DirectoryInfo(".")
Dim dirName As String = dir.Name
Console.WriteLine("DirectoryInfo name is {0}.", dirName)
End Sub
End Class
This Name property returns only the name of the directory, such as "Bin". To get the full path, such as "c:\public\Bin", use the FullName property.
The Name property of a DirectoryInfo requires no permission (beyond the read permission to the directory necessary to construct the Exists) but can give out the directory name. If it is necessary to hand out a DirectoryInfo to a protected directory with a cryptographically secure name, create a dummy directory for the untrusted code's use.
For a list of common I/O tasks, see Common I/O Tasks.
Produkt | Versjoner |
---|---|
.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 |
.NET-tilbakemelding
.NET er et åpen kilde-prosjekt. Velg en kobling for å gi tilbakemelding: