Created
June 7, 2012 16:49
-
-
Save hyperqube/2890001 to your computer and use it in GitHub Desktop.
Split files into roughly equal partitions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Add-Prop([string]$name,$value){ | |
$input |add-member -memberType Noteproperty -name $name -value $value -passThru | |
} | |
function Get-Partitions($no_partitions=4){ | |
$sums = @() | |
$indexes = (0..($no_partitions-1)) | |
$indexes |% { $sums+= 0 } | |
$sortedBySize = $input | Sort Length -Descending | |
foreach($file in $sortedBySize){ | |
$current_min= [System.Int32]::MaxValue | |
foreach( $i in $indexes ){ | |
if( $current_min -gt $sums[ $i ] ) | |
{ | |
$current_min = $sums[ $i ] | |
$index = $i | |
} | |
} | |
$file | Add-Prop Partition $index| Add-Prop RunningSum( $sums[ $index ]+= $file.Length ) | |
} | |
} | |
dir C:\windows\system32\*.dll | Get-Partitions | Select BaseName,Partition,RunningSum| ogv |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment