If you want to do the recursive search yourself, using the
glob function (rather than
opendir and
readdir) makes it somewhat simpler because
glob returns the relative path of the file together with the file. The following program prints only the files, but searches the directories and subdirectories:
use strict;
use warnings;
search_dir (shift);
sub search_dir {
my $path = shift;
my @dir_entries = glob("$path/*");
foreach my $entry (@dir_entries) {
print $entry, "\n" if -f $entry;
search_dir($entry) if -d $entry;
}
}
If you want to print also the directories, you might change the relevant lines to this:
print "$entry is a file \n" if -f $entry;
print "$entry is a dir \n" and search_dir($entry) if -d $entry
+;