Skip to content

Instantly share code, notes, and snippets.

@hyperqube
Created June 7, 2012 16:49
Show Gist options
  • Save hyperqube/2890001 to your computer and use it in GitHub Desktop.
Save hyperqube/2890001 to your computer and use it in GitHub Desktop.
Split files into roughly equal partitions
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