ISEFileCollection 对象
ISEFileCollection 对象是 ISEFile 对象的集合。 例如 $psISE.CurrentPowerShellTab.Files
集合。
方法
Add([FullPath] )
在 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")
Remove(文件、[强制] )
在 Windows PowerShell ISE 2.0 及更高版本中受支持。
从当前 PowerShell 选项卡中删除指定文件。
文件 - 字符串要从集合中删除的 ISEFile 文件。 如果文件尚未保存,此方法将引发异常。 使用 Force switch 参数强制删除未保存的文件。
[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)
SetSelectedFile(selectedFile)
在 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 对象模型层次结构