ISEFile 对象

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

方法

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(filename, [saveEncoding])

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

使用指定的文件名和编码保存文件。

文件名 - 字符串要用于保存文件的名称。

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

异常

  • 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)

性能

DisplayName

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

只读属性,用于获取包含此文件的显示名称的字符串。 名称显示在编辑器顶部的“文件”选项卡上。 名称末尾存在星号 (*) 表示文件已更改尚未保存。

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

编辑 器

在 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

IsUntitled

在 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

另请参阅