パスの解析(parse-path)(1)

※「parse-path」はPowerShell 1.0では「Split-Path」という名前に変更されています。
「parse-path」はパスの解析を行うCmdletです。
パスは、ファイル/レジストリの両方に対応可能です。

「parse-path」:ファイルパスの解析

親フォルダの取得
MSH C:\> parse-path "C:\Program Files\Microsoft Command Shell" -parent
C:\Program Files
ドライブの取得
MSH C:\> parse-path "C:\Program Files\Microsoft Command Shell" -qualifier
C:
ファイル/末端フォルダの取得
MSH C:\> parse-path "C:\Program Files\Microsoft Command Shell" -leaf
Microsoft Command Shell
MSH C:\> parse-path "C:\Program Files\Microsoft Command Shell\msh.exe" -leaf
msh.exe

「parse-path」:ファイルパスの解析(パスの存在チェック付き)

resolveオプションを指定すると、パスの存在チェックを行います。
以下は、「C:\AAA\BBB」というパスが存在しない場合のサンプルです。

パスが存在しない場合
MSH C:\> parse-path C:\AAA\BBB -parent -resolve
parse-path : Cannot find path 'C:\AAA\BBB' because it does not exist.
At line:1 char:11
+ parse-path  <<<< C:\AAA\BBB -parent -resolve

MSH C:\> parse-path C:\AAA\BBB -qualifier -resolve
parse-path : Cannot find path 'C:\AAA\BBB' because it does not exist.
At line:1 char:11
+ parse-path  <<<< C:\AAA\BBB -qualifier -resolve