1024) { if ($tmp > 1048576) { if ($tmp > 1073741824) { if ($tmp > 1099511627776) { if ($tmp > 1125899906842624) { if ($tmp > 1152921504606847000) { if ($tmp > 1180591620717411300000) { $u="o";$tmp=$tmp/1180591620717411300000; } else { $u="e";$tmp=$tmp/1152921504606847000; } } else { $u="p";$tmp=$tmp/1125899906842624; } } else { $u="t";$tmp=$tmp/1099511627776; } } else { $u="g";$tmp=$tmp/1073741824; } } else { $u="m";$tmp=$tmp/1048576; } } else { $u="k";$tmp=$tmp/1024; } } else { $u=""; } return round($tmp, 2)." ".$u."b"; } function _o($x) { echo $x."\n"; } function rddir($dir) { /* v2.11 */ global $tfile,$tdir,$ij;$i=0;$j=count($tdir); if (is_dir($dir)) { if ($dh=opendir($dir)) { while (($file=readdir($dh)) !== false) { if (is_dir($dir.$file)) { if (($file != ".") && ($file != "..")) { $tdir[$j]=$dir.$file;$j++; } } else { $tfile[$i]=$file;$i++; } } closedir($dh); } } $ij=$i; } // main if (!isset($argv[1])) { _o("Usage: ".$_SERVER['PHP_SELF']." [move_to]\nEg: ".$_SERVER['PHP_SELF']." path/to/folder path/to/compilation/folder");die; } define('move_to',(isset($_argv[2])) ? $argv[2] : "_disk_compilations_"); // collect file sizes and paths for ($tsk=$tdk=$tsz=$i=0,$files=array(),$sizes=array(),$flag=array(),$tdir[0]=$argv[1];$i 0) && ($sz <= dsize)) { $files[]=$fn; $sizes[]=$sz; $flag[]=1; } else { _o($fn." skipped.");$tsk++; } } elseif ((is_dir($fn)) && ($tfile[$j] != ".") && ($tfile[$j] != "..")) { $tdir[]=$fn; } } unset($tfile); } } // build compilations _o("Building Compilations..."); while (in_array(1,$flag)) { // loop until there's nothing left for ($k=array_keys($flag,1),$fl=array(),$sz=$i=0,$j=count($k);$i<$j;$i++) { if (($sizes[$k[$i]]+$sz) < dsize) { // search for files that fits/still fitting on this disk $sz+=$sizes[$k[$i]]; $fl[]=$files[$k[$i]]; $flag[$k[$i]]=0; $sd=move_to."/".$tdk."/".dirname($files[$k[$i]]); if (!is_dir($sd)) { mkdir($sd,0755,true); } if (debug) { // just create a zero byte file touch(move_to."/".$tdk."/".$files[$k[$i]]); } else { rename($files[$k[$i]],move_to."/".$tdk."/".$files[$k[$i]]); } } } $tdk++; $tsz+=$sz; if (debug) { _o(var_export($fl,true)."\nSize:".$sz."\n"); } } _o("Found: ".bytec($tsz)." (".number_format($tsz)." bytes) in ".number_format(count($flag))." files (".$tsk." skipped)\nIdeal disk count: ".round($tsz/dsize,3)." did: ".$tdk); ?>