Tolgar
asked on
What value should I assign to maxdepth if I want to search to the deepest point of the directory structure in Perl?
Hi,
I use the following code to find files in a directory and its subdirectories:
What value should I assign to $depth if I want to search to the deepest point of the directory structure?
My temporary solution is to assign a very high value but I'd like to make it more robust.
I tried 0 but it didn't work.
Thanks,
I use the following code to find files in a directory and its subdirectories:
sub findFiles(){
my ($fileType, $depth, $directory) = @_;
my @files = File::Find::Rule->file()
->name( "*.$fileType" )
->maxdepth( $depth )
->in( $directory );
return (\@files);
What value should I assign to $depth if I want to search to the deepest point of the directory structure?
My temporary solution is to assign a very high value but I'd like to make it more robust.
I tried 0 but it didn't work.
Thanks,
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Alternitively rewrite the function, to validate the passed arguments and only add a maxdepth, if required e.g.
sub findFiles(){
my ($fileType, $depth, $directory) = @_;
my($rule, @files);
$rule = File::Find::Rule->new;
$rule->file;
$rule->name( "*.$fileType") if $fileType ;
$rule->maxdepth( $depth) if ($depth && $depth > 0) ;
@files = $rule->in( $directory ) if $directory;
return (\@files);
ASKER
As I see, you recommend me to put a very large number.
Is there any other way of doing it other than assigning a hard coded number.
Thanks,