Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
|
|
@ -0,0 +1,27 @@
|
|||
<#
|
||||
.Synopsis
|
||||
Finds the deepest common directory path of files passed through the pipeline.
|
||||
.Parameter File
|
||||
PowerShell file object.
|
||||
#>
|
||||
function Get-CommonPath {
|
||||
[CmdletBinding()]
|
||||
param (
|
||||
[Parameter(Mandatory=$true, ValueFromPipeline=$true)]
|
||||
[System.IO.FileInfo] $File
|
||||
)
|
||||
process {
|
||||
# Get the current file's path list
|
||||
$PathList = $File.FullName -split "\$([IO.Path]::DirectorySeparatorChar)"
|
||||
# Get the most common path list
|
||||
if ($CommonPathList) {
|
||||
$CommonPathList = (Compare-Object -ReferenceObject $CommonPathList -DifferenceObject $PathList -IncludeEqual `
|
||||
-ExcludeDifferent -SyncWindow 0).InputObject
|
||||
} else {
|
||||
$CommonPathList = $PathList
|
||||
}
|
||||
}
|
||||
end {
|
||||
$CommonPathList -join [IO.Path]::DirectorySeparatorChar
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
"C:\a\b\c\d\e","C:\a\b\e\f","C:\a\b\c\d\x" | Get-CommonPath
|
||||
C:\a\b
|
||||
Loading…
Add table
Add a link
Reference in a new issue