in reply to Re: How do I read all files in a directory recursively?
in thread How do I read all files in a directory recursively?

One minor problem with the above code.. The opendir command is done relative to the current directory. If you were to opendir('dir1'), you would be looking in pwd/dir1. If you then found a directory inside of dir1 named dir2, an opendir('dir2') would look for pwd/dir2, which is not the desired result. To get the recursion right, the recurse_dir would have to look something like
sub recurse_dir { my $dir = shift(); opendir D, $dir; while (readdir D) { process_file ($dir/$_) if -f $dir/$_; recurse_dir ($dir/$_) if -d _; } closedir D; }
Either that, or the recurse_dir function could chdir in to each directory and chdir .. after the while loop.