Useful bit of Perl code – folk at work found this useful approach on the web somewhere – it’s much quicker than doing a recursive find apparently:
my @dirlist = ();
sub process_files
{
my $path = shift;
opendir (DIR, $path) or die “Unable to open $path: $!”;
my @files =
map { $path . ‘\’ . $_ }
grep { !/^.{1,2}$/ }
readdir (DIR);
closedir (DIR);
for (@files)
{
if (-d $_))
{
print $_.”n”;
push @dirlist, $_;
push @files, process_files ($_);
}
}
}
process_files(“.”);
Pardon the indentation/formatting 😉
Cheers,
Don
Discover more from Don's Blog
Subscribe to get the latest posts sent to your email.
Here’s the original page with more detail:
http://www.perlmonks.org/?node_id=136482
Hi Don,
http://wiht.link/perl-resources
Thanks,
-Tom