2016-07-13 2 views
1

경로 예 : 'C : \ 폴 데라 \ folderB \ folderC \ script.ps1'Split-Path를 사용PowerShell 2 경로에서 폴더 가져 오기?

, 내가 'folderC'를 얻을 수 있어요,하지만 난 방법을 얻을 것 'folderB'?

Split-Path (Split-Path $MyInvocation.MyCommand.Definition -Parent) -Leaf 

이렇게하면 folderC가 반환됩니다.

답변

1

그럼 당신은 그냥이

Split-Path $MyInvocation.MyCommand.Definition -Parent | 
    Split-Path -Parent | 
    Split-Path -Leaf 
과 같을 것이다 파이프 라인으로 다른 Split-Path

Split-Path (Split-Path (Split-Path $MyInvocation.MyCommand.Definition -Parent) -Parent) -Leaf 

를 추가 할 수 있습니다