DirectoryInfo.Name DirectoryInfo.Name DirectoryInfo.Name DirectoryInfo.Name Property

定義

取得這個 DirectoryInfo 執行個體的名稱。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.

範例

下列範例只會顯示目前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.

的屬性不需要許可權(除了結構Exists的讀取權限之外),但可以提供目錄名稱。 DirectoryInfo NameThe 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.

適用於

另請參閱