# This is another way to traverse directories and files recursively, # but the above method (using opendir()) is my choice. # Test both of them out and see for yourself... use strict; use warnings; use IO::Dir; use Time::HiRes; my $base_dir = "/"; my $file_count = 0; my @dir_list; my %dir; while($base_dir) { %dir = get_dir_listing($base_dir); my ($key, $el) = each %dir; while($key) { if(-d "$base_dir$key" && $key!~/^\.{1,2}$/) { push(@dir_list, "$base_dir$key/"); }elsif(-f "$base_dir$key") { $file_count++; print "File: $base_dir$key\n"; } ($key, $el) = each %dir; } $base_dir = shift(@dir_list); } my $elapsed_time = (Time::HiRes::time-$^T); print "Completed listing in: $elapsed_time seconds\n"; print "Total files: $file_count\n"; sub get_dir_listing { my $base_dir = $_[0]; tie %dir, "IO::Dir", "$base_dir"; return %dir; }