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

[玩转系统] ISEFileCollection 对象

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

ISEFileCollection 对象


ISEFileCollection 对象是 ISEFile 对象的集合。一个示例是 $psISE.CurrentPowerShellTab.Files 集合。

方法

添加([完整路径])

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

创建并返回一个新的无标题文件并将其添加到集合中。新创建的文件的 IsUntitled 属性为 $true

[FullPath] - 可选字符串 文件的完整指定路径。如果包含 FullPath 参数和相对路径,或者使用文件名而不是完整路径,则会生成异常。

# Adds a new untitled file to the collection of files in the current PowerShell tab.
$newFile = $psISE.CurrentPowerShellTab.Files.Add()

# Adds a file specified by its full path to the collection of files in the current PowerShell tab.
$psISE.CurrentPowerShellTab.Files.Add("$pshome\Examples\profile.ps1")

删除(文件,[强制])

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

从当前 PowerShell 选项卡中删除指定文件。

文件 - 字符串 要从集合中删除的 ISEFile 文件。如果文件尚未保存,此方法将引发异常。使用Force开关参数强制删除未保存的文件。

[Force] - 可选布尔值 如果设置为 $true,则授予删除文件的权限,即使该文件在上次使用后尚未保存。默认值为 $false

# Removes the first opened file from the file collection associated with the current PowerShell tab.
# If the file has not yet been saved, then an exception is generated.
$firstfile = $psISE.CurrentPowerShellTab.Files[0]
$psISE.CurrentPowerShellTab.Files.Remove($firstfile)

# Removes the first opened file from the file collection associated with the current PowerShell tab, even if it has not been saved.
$firstfile = $psISE.CurrentPowerShellTab.Files[0]
$psISE.CurrentPowerShellTab.Files.Remove($firstfile, $true)

设置选定的文件(选定的文件)

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

选择由 SelectedFile 参数指定的文件。

SelectedFile - Microsoft.PowerShell.Host.ISE.ISEFile 要选择的 ISEFile 文件。

# Selects the specified file.
$firstfile = $psISE.CurrentPowerShellTab.Files[0]
$psISE.CurrentPowerShellTab.Files.SetSelectedFile($firstfile)

参见

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

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

取消回复欢迎 发表评论:

关灯