Thanks for that quick reply
But I have 2 use my @files = `attrib /s c:\\*`; my $n = scalar @files; as without it says that wc is an unrecognised command .Also the I am showing the code of the fastest method I know
use strict;
my $f; # number of files
my $d; # number of dirs
sub count_files
{
my ($ref) = @_;
foreach my $dir (@$ref)
{
$dir = readlink $dir and chop $dir if -l $dir; # read link
next unless opendir(my $dir_h, $dir); # open dir o
++r next
my @dirs;
while (defined(my $file = readdir $dir_h))
{
if ($file eq '.' or $file eq '..') {
next;
}
if (-d "$dir/$file")
{
++$d; # counting d
+irs
push @dirs, "$dir/$file";
}
elsif(-f _)
{
++$f; # counting f
+iles
}
}
closedir $dir_h;
count_files(\@dirs);
}
[$f, $d];
}
foreach my $arg (@ARGV)
{
my @dir = -d $arg ? $arg : next;
($f, $d) = (0, 0);
print "$arg\nFiles\t: $$_[0]\nFolders\t: $$_[1]\n" for count_files
+(\@
dir);
}
suggest a faster method and also how to run without using my @files = `attrib /s c:\\*`; my $n = scalar @files;
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|