語言

FileSystemInfo.Extension 屬性

定義

取得檔名的副檔名部分,包括開頭的點 . ,即使它是整個檔名;若沒有副檔名則是空字串。

public:
 property System::String ^ Extension { System::String ^ get(); };
public string Extension { get; }
member this.Extension : string
Public ReadOnly Property Extension As String

屬性值

包含 FileSystemInfo 擴展的字串。

備註

該 Extension 屬性回傳 FileSystemInfo 副檔名,起始於檔案全名的最後一個點(.)。 例如:

  • 對於檔案 c:\NewFile.txt,此性質會返回 ".txt"。
  • 對於檔案 c:\.gitignore,此性質會返回 ".gitignore"。
  • 對於檔案 c:\noextension,此屬性回傳一個空字串 ""。
  • 對於檔案 c:\a.b.c,此性質會返回 ".c"。
  • 當 由 FileInfo 帶有尾隨點的檔案路徑構成時,該尾隨點會被裁剪,因此 new FileInfo("foo.bar.").Extension 返回 ".bar"。

下表列出其他典型或相關的 I/O 任務範例。

若要這麼做... 請參閱本主題中的範例...
建立文字檔。 如何:將文字寫入檔案
寫入文字檔。 如何:將文字寫入檔案
從文字檔讀取。 如何:從檔案讀取文字
取得檔案的完全限定路徑。 GetFullPath
只取得檔名 a path。 GetFileNameWithoutExtension
只從路徑中取得目錄名稱。 GetDirectoryName
更改檔案的副檔名。 ChangeExtension

適用於

另請參閱