DirectoryInfo.Name 属性


获取此 DirectoryInfo 实例的名称。Gets the name of this DirectoryInfo instance.

 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.


下面的示例仅显示当前 DirectoryInfo 实例的名称。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);
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


Name 属性仅返回目录的名称,如 "Bin"。This Name property returns only the name of the directory, such as "Bin". 若要获取完整路径(例如 "c:\public\Bin"),请使用 FullName 属性。To get the full path, such as "c:\public\Bin", use the FullName property.

DirectoryInfoName 属性无需权限(除了对构造 Exists所需的目录的读取权限),但可以指定目录名称。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. 如果需要使用加密的安全名称将 DirectoryInfo 分发到受保护的目录,请为不受信任的代码使用创建虚拟目录。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.

有关常见 i/o 任务的列表,请参阅常见 I/o 任务For a list of common I/O tasks, see Common I/O Tasks.