15 lines
516 B
Plaintext
15 lines
516 B
Plaintext
Function Get-CommonPath( $Separator, $PathList ){
|
|
$SplitPaths = $PathList | foreach { , $_.Split($Separator) }
|
|
$MinDirectoryDepth = $SplitPaths | Measure-Object -Property Length -Minimum | Select -ExpandProperty Minimum
|
|
$CommonPath = foreach ($Index in 0..($MinDirectoryDepth - 1)) {
|
|
$UniquePath = @($SplitPaths | foreach { $_[$Index] } | Sort -Unique)
|
|
if ($UniquePath.Length -gt 1) {
|
|
break;
|
|
}
|
|
|
|
$UniquePath
|
|
}
|
|
|
|
[String]::Join($Separator, $CommonPath)
|
|
}
|