ISEFileCollection 对象是 ISEFile 对象的集合。与 PowerShellTab 对象关联的文件集合是此类的成员。例如 $psISE.CurrentPowerShellTab.Files 集合。

方法

Add()

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

# Adds a new file to the collection of files in the current PowerShell tab.
$newFile = $psISE.CurrentPowerShellTab.Files.Add() 
# Add the date as the first line of text in the new file.
$newFile.Editor.Text = "#" + (Get-Date) 

Add(string fullPath)

将 fullPath 参数指定的文件添加到文件集合中。新创建的这个文件的 IsUntitled 属性为 false。

注意:

如果使用相对路径或文件名,而不是完整路径,此方法将引发异常。

fullpath
文件的完整指定路径。

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

Remove(Microsoft.PowerShell.Host.ISE.ISEFile file)

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

file
要从集合中删除的 ISEFile。如果文件尚未保存,此方法将引发异常。使用下面的替代方法可以强制删除未保存的文件。

# Removes the first opened file from the file collection associated with the current PowerShell tab.
$firstfile = $psISE.CurrentPowerShellTab.Files[0]
$psISE.CurrentPowerShellTab.Files.Remove($firstfile)

Remove(Microsoft.PowerShell.Host.ISE.ISEFile file, bool force)

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

file
要从集合中删除的 ISEFile。

force
布尔型参数,用于授予删除文件(即使自上次使用后未保存也要删除)的权限。

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

SetSelectedFile(Microsoft.PowerShell.Host.ISE.ISEFile selectedFile)

选择 selectedFile 参数指定的文件。

selectedFile
要选择的 ISEFile。

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

另请参阅




目录