I need to check if my current location contains a directory called _framework and if it does, set the location to that folder.
The Problem is, I don't know what's in the path before my keyword, or after my keyword.
So to visualize, basically if I am here:
C:\foo\bar\some\_framework\stuff\xy
I need to jump here:
C:\foo\bar\some\_framework
I've written a code that works:
$CurrentPath = (Get-Location).Path
$SplitUp = $CurrentPath -split '\\'
$Result = @()
foreach ($Split in $SplitUp) {
$Result += $Split
if ($Split -eq '_framework') { break }
}
Set-Location ($Result -join '\')
but I find it massivelly ugly. is there a simple cmdlet that would give me my desired result in an easier way, without splitting and iterating the result - or ist this the only solution?
It has to be available in PowerShell 5.1