ISEFile 物件代表 Windows PowerShell 整合式指令碼環境 (ISE) 中的檔案。它是 Microsoft.PowerShell.Host.ISE.ISEFile 類別的執行個體。本主題列出這個物件的成員方法和成員屬性。$psISE.CurrentFile 與 Files 集合內的檔案在 Powershell 索引標籤中都是 Microsoft.PowerShell.Host.ISE.ISEFile 類別的執行個體。

方法

Save(System.Text.Encoding saveEncoding)

將檔案儲存到磁碟。

saveEncoding
儲存的檔案所要使用的編碼。

例外狀況
  • System.IO.IOException:無法儲存檔案。

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

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

Save()

儲存檔案。

例外狀況
  • System.IO.IOException:無法儲存檔案。

# Explicitly save the file. 
$psIse.CurrentFile.save()

SaveAs(string fileName)

將檔案儲存成指定的 fileName。

fileName
要另存檔案的名稱。這個方法的預設編碼為 UTF-16。

例外狀況
  • System.ArgumentNullException:fileName 為 null。

  • System.ArgumentException:fileName 空白。

  • System.IO.IOException:無法儲存檔案。

# Explicitly save the file. 
$fullpath = "c:\temp\newname.txt"
$myfile=$psIse.CurrentFile
$myfile.SaveAs($fullPath)

SaveAs(string fileName, System.Text.Encoding saveEncoding)

以指定的編碼將檔案儲存成指定的檔案名稱。

fileName:
要另存檔案的名稱。您可以為檔案指定完整的路徑名稱。

saveEncoding
要儲存檔案的編碼方式。

例外狀況
  • System.ArgumentNullException:fileName 為 null。

  • System.ArgumentException:fileName 空白。

  • System.IO.IOException:無法儲存檔案。

# Explicitly save the file as UTF8.
$fullpath = "c:\temp\newname.txt"
$myfile=$psIse.CurrentFile
$myfile.SaveAs($fullPath, [System.Text.Encoding]::UTF8)
# Gets the current encoding.
$myfile=$psIse.CurrentFile
$myfile.Encoding

屬性

DisplayName

唯讀屬性,取得包含這個檔案之顯示名稱的字串。

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

Editor

唯讀屬性,取得用於指定之檔案的編輯器

# Gets the editor and the text.
$myfile=$psIse.CurrentFile
$myfile.Editor.Text 

編碼

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

# Shows the encoding for the file. 
$myfile=$psIse.CurrentFile
$myfile.Encoding

FullPath

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

# Shows the full path for the file. 
$myfile=$psIse.CurrentFile
$myfile.FullPath

IsSaved

唯讀布林屬性,如果檔案自上次修改後已經儲存,則會傳回 true。

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

IsUntitled

唯讀屬性,如果檔案從未被指定名稱,則為 true。

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

請參閱




目錄