ISEFile 对象

ISEFile 对象表示 Windows PowerShell 集成脚本环境(ISE)中的一个文件。 它是 Microsoft.PowerShell.Host.ISE.ISEFile 类的一个实例。 本主题列出其成员方法和成员属性。 $psISE.CurrentFile PowerShell标签页中文件集合中的文件和文件都是Microsoft.PowerShell.Host.ISE.ISEFile类的实例。

Methods

Save([saveEncoding] )

支持Windows PowerShell ISE 2.0及更高版本。

把文件保存到磁盘。

[saveEncoding] - 可选的 System.Text.Encoding 用于保存文件的可选字符编码参数。 默认值是 UTF8

例外

  • 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

例外

  • System.ArgumentNullException文件名 参数为空。
  • 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

已救

支持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

另请参阅