次の方法で共有


ISEFile オブジェクト

ISEFileオブジェクトは、Windows PowerShell統合スクリプト環境(ISE)におけるファイルを表します。 これは Microsoft.PowerShell.Host.ISE.ISEFile クラスのインスタンスです。 このトピックでは、そのメンバーメソッドとメンバープロパティを一覧にします。 PowerShellタブのFilesコレクションの $psISE.CurrentFile とファイルはすべて Microsoft.PowerShell.Host.ISE.ISEFile クラスのインスタンスです。

Methods

Save([ [ saveEncoding] )

Windows PowerShell ISE 2.0以降でサポートされています。

ファイルをディスクに保存します。

[saveEncoding] - オプションの System.Text.Encoding 保存ファイルに使用されるオプションの文字エンコーディングパラメータ。 デフォルト値は UTF8です。

Exceptions

  • 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(ファイル名、[saveEncoding])

Windows PowerShell ISE 2.0以降でサポートされています。

指定されたファイル名とエンコーディングでファイルを保存します。

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

[saveEncoding] - オプションの System.Text.Encoding 保存ファイルに使用されるオプションの文字エンコーディングパラメータ。 デフォルト値は UTF8です。

Exceptions

  • System.ArgumentNullException: ファイル名 パラメータがnullです。
  • 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

Editor

Windows PowerShell ISE 2.0以降でサポートされています。

指定されたファイルに使われる エディターオブジェクト を取得する読み取り専用プロパティです。

# Gets the editor and the text.
$psISE.CurrentFile.Editor.Text

Encoding

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

無題です

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

こちらもご覧ください