Created
November 20, 2013 16:43
-
-
Save AndrewRussellHayes/7566490 to your computer and use it in GitHub Desktop.
Accepts: directory path
Does: counts files in directory ignoring dotfiles and files named "file_list"
Returns: count as an int
Note: this is probably the fastest "pure perl" way to do this. It is certainly faster than reading the whole file in to an array and then processing through the array. This just processes as the directory is read.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sub getCount{ | |
my $DH; # Directory Handle | |
my $WD = $_[0]; # Working Directory | |
my $DE; # Directory Entry (file) | |
my $CT; # Count | |
$CT=0; | |
opendir($DH, $WD) or die "Cannot open working directory |$WD|: $!"; | |
while ($DE= readdir($DH)) | |
{ | |
next if $DE=~ /^\./ || $DE=~ /file_list/; | |
$CT++; | |
} | |
closedir($DH); | |
return $CT; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment