Count directory entries in given directories


/ Published in: Perl
Save to your folder(s)

In response to a very simplistic solution suggestion using Shell, here is a basic version of what I use. The advantage of the solution below is that it is supposed to be much faster on directories with many files (I regularly use its full-blown version on directories with tens and hundreds of thousands of files).


Copy this code and paste it in your HTML
  1. #!/usr/bin/perl
  2. $ARGV[0] = '.' unless @ARGV;
  3. for my $dir (@ARGV) {
  4. opendir DIR, $dir or die "$dir: $!\n";
  5. $file =~ m:^\.: or ++$count
  6. while ($file = readdir DIR);
  7. closedir DIR;
  8. }
  9. print "$count\n";
  10. exit 0;

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.