共用方式為


ISEFile 物件

ISEFile 物件代表 Windows PowerShell 整合腳本環境(ISE)中的一個檔案。 它是 Microsoft.PowerShell.Host.ISE.ISEFile 類別的實例。 本主題列出其成員方法與成員屬性。 PowerShell 分頁中 Files 集合中的 The $psISE.CurrentFile 和 檔案都是 Microsoft.PowerShell.Host.ISE.ISEFile 類別的實例。

Methods

Save([saveEncoding] )

支援於 Windows PowerShell ISE 2.0 及更新版本。

將檔案儲存到磁碟。

[saveEncoding] - 可選的 System.Text.Encoding 一個可選的字元編碼參數,用於儲存檔案。 預設值為 UTF8

Exceptions

  • System.IO.IOException:檔案無法儲存。
# Save the file using the default encoding (UTF8)
$psISE.CurrentFile.Save()

# Save the file as ASCII.
$psISE.CurrentFile.Save([System.Text.Encoding]::ASCII)

# Gets the current encoding.
$myfile = $psISE.CurrentFile
$myfile.Encoding

SaveAs(檔名,[saveEncoding])

支援於 Windows PowerShell ISE 2.0 及更新版本。

儲存指定檔名和編碼的檔案。

檔名 - 字串 用來儲存檔案的名稱。

[saveEncoding] - 可選的 System.Text.Encoding 一個可選的字元編碼參數,用於儲存檔案。 預設值為 UTF8

Exceptions

  • System.ArgumentNullException檔名 參數為 null。
  • System.ArgumentException檔名 參數為空。
  • System.IO.IOException:檔案無法儲存。
# Save the file with a full path and name.
$fullpath = "C:\temp\newname.txt"
$psISE.CurrentFile.SaveAs($fullPath)
# Save the file with a full path and name and explicitly as UTF8.
$psISE.CurrentFile.SaveAs($fullPath, [System.Text.Encoding]::UTF8)

屬性

顯示名稱

支援於 Windows PowerShell ISE 2.0 及更新版本。

唯讀屬性,取得包含該檔案顯示名稱的字串。 名稱顯示在編輯器頂端的 「檔案 」標籤中。 名稱末尾有星號(*)表示檔案有未被儲存的變更。

# Shows the display name of the file.
$psISE.CurrentFile.DisplayName

Editor

支援於 Windows PowerShell ISE 2.0 及更新版本。

只讀屬性,能取得用於指定檔案的 編輯器物件

# Gets the editor and the text.
$psISE.CurrentFile.Editor.Text

編碼

支援於 Windows PowerShell ISE 2.0 及更新版本。

只讀屬性,取得原始檔案的編碼。 這是一個 System.Text.Encoding 物件。

# Shows the encoding for the file.
$psISE.CurrentFile.Encoding

FullPath

支援於 Windows PowerShell ISE 2.0 及更新版本。

唯讀特性,能取得指定已開啟檔案完整路徑的字串。

# Shows the full path for the file.
$psISE.CurrentFile.FullPath

IsSaved

支援於 Windows PowerShell ISE 2.0 及更新版本。

只有讀取的布林屬性,如果檔案在最後修改後才被儲存,則會回傳 $true

# Determines whether the file has been saved since it was last modified.
$myfile = $psISE.CurrentFile
$myfile.IsSaved

無題

支援於 Windows PowerShell ISE 2.0 及更新版本。

如果檔案從未被賦予標題,則會回傳 $true 唯讀屬性。

# Determines whether the file has never been given a title.
$psISE.CurrentFile.IsUntitled
$psISE.CurrentFile.SaveAs("temp.txt")
$psISE.CurrentFile.IsUntitled

另請參閱