Storage calculator

Discuss and share scripts and script files...
Post Reply
serendipity
Posts: 3360
Joined: 07 May 2007 18:14
Location: NJ/NY

Storage calculator

Post by serendipity »

My father asked me recently, how many CDs will a bunch of folders fit into. After I told him about bits and bytes, he did the math in his head quicker than i could. But i got reminded of this post and went ahead and wrote a script which calculates amount of media you need to store something.

Download:
StorageCalc.xys

Code: Select all

//StorageCalc

//Calculates which media one needs to store selected files.
//Usage: Select files and run this script

  focus;
  status "WAIT! gathering info... (ESC to stop)","FF0000",progress;
  $filecount= get ("CountSelected");
  $files= get("SelectedItemsNames", ", ");
//get folder size  
  #487;    
  //step;
  $allsize= report ("{Size RAW}+",1);
  $total= substr ($allsize, 0,-1);
  replace $total, $total, "-","0";
  $total= eval ($total);    
  

  $totalKB=$total/1024;
  $totalMB=$totalKB/1024;
  $totalGB=$totalMB/1024;
  
  
  IF ($totalKB Like "*.*") {
  $totalKB = substr($totalKB, 0, strpos($totalKB, ".")+3);
  }
  ELSE {
  $totalKB = "$totalKB.00";
  }
  IF ($totalMB Like "*.*") {
  $totalMB = substr($totalMB, 0, strpos($totalMB, ".")+3);
  }
  ELSE {
  $totalMB = "$totalMB.00";
  }
  IF ($totalGB Like "*.*") {
  $totalGB = substr($totalGB, 0, strpos($totalGB, ".")+3);
  }
  ELSE {
  $totalGB = "$totalGB.00";
  }
   
  
  $totaldisplay =   regexreplace($total, "(\d{1,3})(?=(\d{3})+(?!\d))", "$1,") . " bytes."; 
  $totalKBdisplay = regexreplace($totalKB, "(\d{1,3})(?=(\d{3})+(?!\d))", "$1,") . " KB |"; 
  $totalMBdisplay = regexreplace($totalMB, "(\d{1,3})(?=(\d{3})+(?!\d))", "$1,") . " MB |"; 
  $totalGBdisplay = regexreplace($totalGB, "(\d{1,3})(?=(\d{3})+(?!\d))", "$1,") . " GB |"; 

  //step;
  $display = "$totalGBdisplay GB";

  IF($totalGBdisplay < "1"){
  $display = "$totalMBdisplay MB";
  }
  ELSEIF ($totalMBdisplay < "1"){
  $display = "$totalKBdisplay KB";
  }
  ELSEIF($totalKBdisplay < "1"){
  $display = "$totaldisplay bytes";
  }
    

  $Ddvd=9*1024*1024*1024;
  $dvd=4.5*1024*1024*1024;
  $cd=700*1024*1024; 
  $iom=100*1024*1024;
  $flop=1.44*1024*1024;

  $cur_Ddvd= $total/$Ddvd;
  $cur_dvd= $total/$dvd;
  $cur_cd= $total/$cd;
  $cur_iom= $total/$iom;
  $cur_flop= $total/$flop;

  //step;
  $DdvdInt= gettoken ($cur_Ddvd, 1, ".");
  
  IF($DdvdInt=="0"){
  $DdvdInt=1;
  $DdvdRem= '0.'.gettoken ($cur_Ddvd, 2, ".");
  $DdvdRem= round((9 * 1024) - (1024 * 9 * $DdvdRem),3);
  }
  ELSE{
  $DdvdInt++;
  $DdvdRem= '0.'.gettoken ($cur_Ddvd, 2, ".");
  $DdvdRem= round((9 * 1024) - (1024 * 9 * $DdvdRem),3);
  }

  $dvdInt= gettoken ($cur_dvd, 1, ".");
  IF($dvdInt=="0"){
  $dvdInt=1;
  $dvdRem= '0.'.gettoken ($cur_dvd, 2, ".");
  $dvdRem= round((4.5 * 1024) - (1024 * 4.5 * $dvdRem),3);
  }
  ELSE{
  $dvdInt++;
  $dvdRem= '0.'.gettoken ($cur_dvd, 2, ".");
  $dvdRem= round((4.5 * 1024) - (1024 * 4.5 * $dvdRem),3);
  }  

  $cdInt= gettoken ($cur_cd, 1, ".");
  IF($cdInt=="0"){
  $cdInt=1;
  $cdRem= '0.'.gettoken ($cur_cd, 2, ".");
  $cdRem= round(700 - ($cdRem *700) ,3);
  }
  ELSE{
  $cdInt++;
  $cdRem= '0.'.gettoken ($cur_cd, 2, ".");
  $cdRem= round(700 - ($cdRem *700) ,3);
  }

  $iomInt= gettoken ($cur_iom, 1, ".");
  IF($iomInt=="0"){
  $iomInt=1;
  $iomRem= '0.'.gettoken ($cur_iom, 2, ".");
  $iomRem= round(100 - ($iomRem * 100) ,3);
  }
   ELSE{
  $iomInt++;
  $iomRem= '0.'.gettoken ($cur_iom, 2, ".");
  $iomRem= round(100 - ($iomRem * 100) ,3);
  }

  $flopInt= gettoken ($cur_flop, 1, ".");
  IF($flopInt=="0"){
  $flopInt=1;
  $flopRem= '0.'.gettoken ($cur_flop, 2, ".");
  $flopRem= round(1.44 - ($flopRem * 1.44), 3);
  }
   ELSE{
  $flopInt++;
  $flopRem= '0.'.gettoken ($cur_flop, 2, ".");
  $flopRem= round(1.44 - ($flopRem * 1.44), 3);
  }

  $DdvdRem =   regexreplace($DdvdRem, "(\d{1,3})(?=(\d{3})+(?!\d))", "$1,"); 
  $dvdRem =   regexreplace($dvdRem, "(\d{1,3})(?=(\d{3})+(?!\d))", "$1,"); 
  $cdRem = regexreplace($cdRem, "(\d{1,3})(?=(\d{3})+(?!\d))", "$1,"); 
  $iomRem = regexreplace($iomRem, "(\d{1,3})(?=(\d{3})+(?!\d))", "$1,"); 
  $flopRem = regexreplace($flopRem, "(\d{1,3})(?=(\d{3})+(?!\d))", "$1,");

  $output =<<<OUT
$filecount File(s): $files<br>
  Size: $totalGBdisplay $totalMBdisplay $totalKBdisplay $totaldisplay
  -------------------------------------------------------------------
  require... <br>
  $DdvdInt x 9GB dual layer DVD(s) with $DdvdRem MB free space (or)<br>  
  $dvdInt x 4.5GB DVD(s) with $dvdRem MB free space (or)<br>  
  $cdInt x 700MB CD(s) with $cdRem MB free space (or)<br>
  $iomInt x 100MB iomega disk(s) with $iomRem MB free space (or)<br>  
  $flopInt x 1.44MB floppy disk(s) with $flopRem MB free space.<br>
OUT;
  status "Done";
  text ("$output",,,,w);


To see the attached files, you need to log into the forum.

Post Reply