ISEFile オブジェクト

ISEFile オブジェクトは、Windows PowerShell Integrated Scripting Environment (ISE) のファイルを表します。 これは Microsoft.PowerShell.Host.ISE.ISEFile クラスのインスタンスです。 このトピックでは、そのメンバー メソッドとメンバー プロパティについて説明します。 $psISE.CurrentFile と、PowerShell タブのファイル コレクション内のファイルは、**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 以降でサポートされています。

指定したファイル名およびエンコードでファイルを保存します。

filename - ファイルを保存するために使用する名前の文字列。

[saveEncoding] - 省略可能な System.Text.Encoding。保存したファイルで使用する省略可能な文字エンコード パラメーター。 既定値は UTF8 です。

例外

  • System.ArgumentNullException: filename パラメーターが null です。
  • System.ArgumentException: filename パラメータが空です。
  • 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)

Properties

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

参照