3 ###############################################################################
6 # Author : Chris Koeritz #
7 # Rights : Copyright (C) 2000-$now by Author #
11 # Provides a somewhat stylized directory lister. #
13 ###############################################################################
14 # This program is free software; you can redistribute it and/or modify it #
15 # under the terms of the GNU General Public License as published by the Free #
16 # Software Foundation; either version 2 of the License or (at your option) #
17 # any later version. See: "http://www.gruntose.com/Info/GNU/GPL.html" for a #
18 # version of the License. Please send any updates to "fred@gruntose.com". #
19 ###############################################################################
21 require "filename_helper.pl";
25 local($chewed_line) = "";
27 local($print_list) = "";
29 # if there were no parameters, we make the default listing for the current
32 $print_list = "Current Directory";
35 local(@munged_list) = &patch_name_for_pc(&remove_trailing_slashes(@ARGV));
36 $print_list = "@munged_list";
37 @arg_list = &glob_list(@ARGV);
40 foreach $dir (@arg_list) {
41 $chewed_line = $chewed_line . " \"$dir\"";
44 if ("$chewed_line" eq "") {
45 print "No files matched that path specification.\n";
49 # show the header, now that we know there's something to print.
50 print "[" . $print_list . "]\n\n";
52 ##print "chewed_line is: $chewed_line\n";
54 local($temp_file)=`mktemp "$TMP/zz_frdsumdir.XXXXXX"`;
57 system("ls -hlF $chewed_line >$temp_file");
59 ##print "file is: $temp_file\n";
61 # drop the main payload, the list of directory info.
62 system("cat $temp_file");
66 # open the file and process the lines to get file lengths.
67 open(DIRLIST, "<$temp_file");
68 # we only want to match ls -al style output lines, and only want to keep the size.
69 $pattern="^[^ ]+ +[^ ]+ +[^ ]+ +[^ ]+ +([0-9.]+[KMG]?).*\$";
70 foreach $file_line (<DIRLIST>) {
71 if ($file_line =~ /$pattern/) {
72 (local $munged = $file_line) =~ s/$pattern/\1/;
73 #print "munge=$munged\n";
74 if ($munged =~ /K$/) {
77 #print "K munged is now $munged\n";
79 if ($munged =~ /M$/) {
81 $munged *= 1024.0 * 1024.0;
82 #print "M munged is now $munged\n";
84 if ($munged =~ /G$/) {
86 $munged *= 1024.0 * 1024.0 * 1024.0;
87 #print "G munged is now $munged\n";
93 unlink($temp_file); # clean up.
95 #print "lens are: $lengths\n";
97 local($total)=int($lengths);
98 local($kbytes)=int($total / 102.4) / 10;
99 local($mbytes)=int($kbytes / 102.4) / 10;
102 print "These files occupy $total bytes ($kbytes KB / $mbytes MB).\n";
103 print "Overall Drive Usage (megs):\n";
105 system("df -m $chewed_line >$temp_file");
107 # now eat the file again, but this time to get drive space info.
108 open(DIRLIST, "<$temp_file");
109 local($space_info) = "";
110 local($did_title) = 0; # true if we have printed the title by now.
111 foreach $file_line (<DIRLIST>) {
112 ($space_info = $file_line) =~ s/[^ ]* *([^ ]*) *([^ ]*) *([^ ]*) *([^ ]*) *.*$/\1 \2 \3 \4/;
114 # if the title hasn't been printed yet, we take some of the info out of
115 # the line and use it for the right sense of the last column.
116 print "Total Used Free ";
117 $space_info =~ s/[^ ]* *[^ ]* *[^ ]* *([^ ]*)/\1/;
124 unlink($temp_file); # clean up.
126 print "$space_info\n";