<?xml version="1.0" encoding="windows-1252"?>
<node id="946583" title="Re^4: fast count files" created="2012-01-06 06:23:48" updated="2012-01-06 06:23:48">
<type id="11">
note</type>
<author id="946540">
gautamparimoo</author>
<data>
<field name="doctext">
&lt;p&gt;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 
&lt;/p&gt;
&lt;code&gt;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 dirs
                push @dirs, "$dir/$file";
            }
            elsif(-f _)
			{
                ++$f;                                     # counting files
            }
        }
        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);
}
&lt;/code&gt;
&lt;p&gt;suggest a faster method and also how to run without using my @files = `attrib /s c:\\*`; my $n = scalar @files;
&lt;/p&gt;</field>
<field name="root_node">
946545</field>
<field name="parent_node">
946567</field>
</data>
</node>
