I have a path, such as D:\repos\my-repo\some\script\path.ps1
, and I want to get the path just up to the repo name: D:\repos\my-repo
. What's the best way to accomplish this? Here's what I've got right now:
$fullPath = $MyInvocation.MyCommand.Path # D:\repos\my-repo\some\script\path.ps1
"{0}my-repo" -f [regex]::Split($fullPath, 'my-repo')[0]
This works but it's pretty ugly and inefficient in my opinion. Is there a better way to accomplish this?