Tuesday, 23 April 2013

Print total count of files recursively in a directory

#!/usr/bin/perl

use strict;
use warnings;
use Cwd;
use File::Find;

my $dir = getcwd ; # Get the current working directory
my $filename = $ARGV[0];
my $counter = 0;
my $file_counter = 0;
find(\&wanted, $dir);
print "Found $counter files at and below $dir\n";

sub wanted {
    -f && $counter++; # Only count files
    }

No comments:

Post a Comment

Tweets by @sriramperumalla