Family Day update

This commit is contained in:
Ingy döt Net 2020-02-17 23:21:07 -08:00
parent aac6731f2c
commit 9ad63ea473
2442 changed files with 39761 additions and 8255 deletions

View file

@ -1,26 +1,27 @@
# Find Common Directory Path
# Input is an array of strings holding the paths
function Get-CommonDirectoryPath($paths){
# Convert each path into array of tokens (i.e. convert array into jagged array)
for($i=0; $i -lt $paths.Count; $i++) {
$paths[$i] = ($paths[$i].TrimStart('/').Split('/'))
}
# Loop through tokens
$c = -1
$found = $false
do { # Do Until loop used to handle paths with different number of directories
$t = $paths[0][++$c]
for($r = 1; $r -lt $paths.Count; $r++) {
if ($t -ne $paths[$r][$c]) { $found=$true; break }
}
} until ($found)
# Return the answer
for($i=0; $i -lt $c; $i++) {$s += "/"+$paths[0][$i]}
return $s
<#
.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
}
}
# Main Entry Point
"The common directory path is " + (Get-CommonDirectoryPath ("/home/user1/tmp/coverage/test", "/home/user1/tmp/covert/operator", "/home/user1/tmp/coven/members"))

View file

@ -1 +1,2 @@
The common directory path is /home/user1/tmp
"C:\a\b\c\d\e","C:\a\b\e\f","C:\a\b\c\d\x" | Get-CommonPath
C:\a\b