updated to not yell about missing visual studio.
[feisty_meow.git] / scripts / files / summing_dir.pl
index a305c748fedc242e680b2f49d97f1cbaa4cee049..d23c5b486a4797e0fe24201c87d0cd37582b07ad 100644 (file)
@@ -19,7 +19,8 @@
 ###############################################################################
 
 require "filename_helper.pl";
-require "importenv.pl";
+
+use Env qw(TMP);
 
 local($chewed_line) = "";
 local(@arg_list);
@@ -53,7 +54,7 @@ print "[" . $print_list . "]\n\n";
 local($temp_file)=`mktemp "$TMP/zz_frdsumdir.XXXXXX"`;
 chop($temp_file);
 
-system("ls -lF $chewed_line >$temp_file");
+system("ls -hlF $chewed_line >$temp_file");
 
 ##print "file is: $temp_file\n";
 
@@ -64,17 +65,36 @@ local($lengths) = 0;
 
 # open the file and process the lines to get file lengths.
 open(DIRLIST, "<$temp_file");
+# we only want to match ls -al style output lines, and only want to keep the size.
+$pattern="^[^ ]+ +[^ ]+ +[^ ]+ +[^ ]+ +([0-9.]+[KMG]?).*\$";
 foreach $file_line (<DIRLIST>) {
-  (local $munged = $file_line) =~ s/^[^ ]* *[^ ]* *[^ ]* *[^ ]* *([0-9]+).*$/\1/;
-#  print "munge=$munged\n";
-  $lengths += $munged;
+  if ($file_line =~ /$pattern/) {
+    (local $munged = $file_line) =~ s/$pattern/\1/;
+    #print "munge=$munged\n";
+    if ($munged =~ /K$/) {
+      chop $munged;
+      $munged *= 1024.0;
+      #print "K munged is now $munged\n";
+    }
+    if ($munged =~ /M$/) {
+      chop $munged;
+      $munged *= 1024.0 * 1024.0;
+      #print "M munged is now $munged\n";
+    }
+    if ($munged =~ /G$/) {
+      chop $munged;
+      $munged *= 1024.0 * 1024.0 * 1024.0;
+      #print "G munged is now $munged\n";
+    }
+    $lengths += $munged;
+  }
 }
 close(DIRLIST);
 unlink($temp_file);  # clean up.
 
 #print "lens are: $lengths\n";
 
-local($total)=$lengths;
+local($total)=int($lengths);
 local($kbytes)=int($total / 102.4) / 10;
 local($mbytes)=int($kbytes / 102.4) / 10;