FileSystemInfo.Extension Property
Definition
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 extension part of the file name, including the leading dot .
even if it is the entire file name, or an empty string if no extension is present.
public:
property System::String ^ Extension { System::String ^ get(); };
public string Extension { get; }
member this.Extension : string
Public ReadOnly Property Extension As String
Property Value
A string containing the FileSystemInfo extension.
Remarks
The Extension
property returns the FileSystemInfo extension, which starts at, and includes, the last dot (.
) in the file's full name. For example:
- For a file
c:\NewFile.txt
, this property returns".txt"
. - For a file
c:\.gitignore
, this property returns".gitignore"
. - For a file
c:\noextension
, this property returns an empty string""
. - For a file
c:\a.b.c
, this property returns".c"
. - When the
FileInfo
is constructed from a file path with a trailing dot, then that trailing dot is trimmed, sonew FileInfo("foo.bar.").Extension
returns".bar"
.
The following table lists examples of other typical or related I/O tasks.
To do this... | See the example in this topic... |
---|---|
Create a text file. | How to: Write Text to a File |
Write to a text file. | How to: Write Text to a File |
Read from a text file. | How to: Read Text from a File |
Retrieve the fully qualified path of a file. | GetFullPath |
Retrieve only the file name a path. | GetFileNameWithoutExtension |
Retrieve only the directory name from a path. | GetDirectoryName |
Change the extension of a file. | ChangeExtension |
Applies to
See also
GitHub에서 Microsoft와 공동 작업
이 콘텐츠의 원본은 GitHub에서 찾을 수 있으며, 여기서 문제와 끌어오기 요청을 만들고 검토할 수도 있습니다. 자세한 내용은 참여자 가이드를 참조하세요.
.NET