当前位置:网站首页 > 更多 > 玩电脑 > 正文

[玩转系统] ISEFile 对象

作者:精品下载站 日期:2024-12-14 02:59:52 浏览:15 分类:玩电脑

ISEFile 对象


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

方法

保存([保存编码])

在 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

另存为(文件名,[保存编码])

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

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

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

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

特性

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

参见

  • ISEFileCollection对象
  • Windows PowerShell ISE 脚本对象模型的用途
  • ISE 对象模型层次结构

您需要 登录账户 后才能发表评论

取消回复欢迎 发表评论:

关灯