X-Git-Url: https://feistymeow.org/gitweb/?a=blobdiff_plain;f=scripts%2Ffiles%2Fsumming_dir.pl;h=82f4d29e0397fee5d36bc0af71874a0f6fdaa1f6;hb=a1c9e3765ab9d0d36e97226a363707f4119ee694;hp=a305c748fedc242e680b2f49d97f1cbaa4cee049;hpb=2952ccf47b80174880141a7ecfa122089f349b8d;p=feisty_meow.git diff --git a/scripts/files/summing_dir.pl b/scripts/files/summing_dir.pl index a305c748..82f4d29e 100644 --- a/scripts/files/summing_dir.pl +++ b/scripts/files/summing_dir.pl @@ -19,7 +19,8 @@ ############################################################################### require "filename_helper.pl"; -require "importenv.pl"; + +use Env qw($TMP $color_add $ls_dot_add $TERM); local($chewed_line) = ""; local(@arg_list); @@ -36,7 +37,11 @@ if ($#ARGV < 0) { @arg_list = &glob_list(@ARGV); } +# add parameters to our chewed_line, but skip items if they are flags we don't +# implement. foreach $dir (@arg_list) { + if ($dir eq "-al") { next; } # skip ls directives. + if ($dir eq "-l") { next; } # skip ls directives. $chewed_line = $chewed_line . " \"$dir\""; } @@ -48,38 +53,62 @@ if ("$chewed_line" eq "") { # show the header, now that we know there's something to print. print "[" . $print_list . "]\n\n"; -##print "chewed_line is: $chewed_line\n"; - local($temp_file)=`mktemp "$TMP/zz_frdsumdir.XXXXXX"`; chop($temp_file); -system("ls -lF $chewed_line >$temp_file"); - -##print "file is: $temp_file\n"; - -# drop the main payload, the list of directory info. -system("cat $temp_file"); +# drop the main payload, the list of directory info, but also save that +# info to a file for analysis. +system("ls -HhlF $ls_dot_add $color_add $chewed_line"); +system("ls -HhlF $ls_dot_add $color_add $chewed_line > $temp_file"); + # the color_add variable, if defined, will have flags for setting the + # directory listing color scheme. 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 () { - (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/; + 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; +local($gbytes)=int($mbytes / 102.4) / 10; print "\n"; -print "These files occupy $total bytes ($kbytes KB / $mbytes MB).\n"; +# print a fancy listing showing bytes at least, but only showing mb and gb if appropriate. +print "These files occupy $total bytes ($kbytes KB"; +if ($mbytes ne 0) { + print " / $mbytes MB"; +} +if ($gbytes ne 0) { + print " / $gbytes GB"; +} +print ").\n"; + print "Overall Drive Usage (megs):\n"; system("df -m $chewed_line >$temp_file");