Advertisement
Guest User

John

a guest
Feb 4th, 2010
757
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?
  2.  
  3. global $mp3s,$i,$j,$b,$perc_t;
  4.  
  5. // **********************************************************************
  6. // VARS
  7. // **********************************************************************
  8.  
  9. $mp3s = array ();
  10. $mp3dir = "F://mp3";
  11. $targetdir = "C://apps//test//";
  12. //$maxsize = 50000000; // 50 mb
  13. $maxsize = 500000000; // 500 mb
  14. //$maxsize = 6000000000; // 6000 mb
  15. $i=0;
  16. $j=0;
  17. $b=0;
  18. $totalsize=0;
  19. $perc_t=0;
  20. $m=0;
  21.  
  22. // **********************************************************************
  23. // FUNCTIONS
  24. // **********************************************************************
  25.  
  26. function read_dir($dir) {
  27.   global $mp3s,$i,$j,$b;
  28.   $d = dir($dir);
  29.   while (false !== ($entry = $d->read())) {
  30.     if ($entry[0] != ".") {
  31.       if (is_dir($dir."//".$entry)) {
  32.         read_dir($dir."//".$entry);
  33.       } else {
  34.         if (substr($entry,strlen($entry)-3,3) == "mp3") {
  35.           $mp3s[$i]['dir'] = $dir."//";
  36.           $mp3s[$i]['filename'] = $entry;
  37.           $mp3s[$i]['filesize'] = @filesize($dir."//".$entry);
  38.           $b = $b + $mp3s[$i]['filesize'];
  39.           $i++;
  40.         } else {
  41.           $j++;
  42.         }
  43.       }
  44.     }
  45.   }
  46. }
  47.  
  48. function print_perc($perc) {
  49.   global $perc_t;
  50.   $step=5;
  51.   if ($perc > $perc_t) {
  52.     $perc_t += $step;
  53.     return $perc . "%\n";
  54.   }
  55. }
  56.  
  57. // **********************************************************************
  58. // MAIN PROGRAM
  59. // **********************************************************************
  60.  
  61. // READ MP3 FILES
  62. if (is_dir($mp3dir)) {
  63.   read_dir($mp3dir);  
  64. }
  65.  
  66. // SEARCH INFORMATION
  67. echo "A total of " . $i . " mp3 files are found\n";
  68. echo "Also, " . $j . " other files were found, bringing a total of " . ($i+$j) . " files\n";
  69. echo "Total mp3 size is " . $b . " bytes\n";
  70. echo "Average mp3 filesize is " . round($b/$i,0) . " bytes\n";
  71. echo "Targetdir limit is " . $maxsize . " bytes\n";
  72. echo "Checking for disk space ... ";
  73. if (disk_free_space($targetdir) > $maxsize) {
  74.   echo "OK\n";
  75. } else {
  76.   $maxsize = disk_free_space($targetdir) - 1000;
  77.   echo "WARNING, not enough disk space. Setting maxsize to " . $maxsize . "\n";
  78. }
  79. echo "Estimate number of mp3 files that will be copied is " . round($maxsize/($b/$i)) . "\n";
  80.  
  81.  
  82. // COPY MP3 FILES
  83. while ($totalsize < $maxsize) {
  84.   $n = rand(0,$i);
  85.   if (($totalsize+$mp3s[$n]['filesize']) < $maxsize) {
  86.     //copy($mp3s[$n]['dir'].$mp3s[$n]['filename'],$targetdir.$mp3s[$n]['filename']);
  87.     $totalsize += $mp3s[$n]['filesize'];
  88.     // calculate %
  89.     echo print_perc (round($totalsize / $maxsize * 100,0));
  90.     $m++;
  91.   } else {
  92.     $totalsize += $mp3s[$n]['filesize'];
  93.   }
  94. }
  95.  
  96. echo $m . " mp3 files copied to " . $targetdir . "\n";
  97.  
  98. ?>
Advertisement
Advertisement
Advertisement
RAW Paste Data Copied
Advertisement