M
Mark
I am using File::Find to process files in a specified directory tree.
I would like to be have find() only traverse a top level directory
(controlling how deep to go would also be helpful).
This is the best I could do. This code breaks if a relative directory
path is specified. It seems that File::Find should provide a way to
specify the maximum depth but I could not find anything.
use strict ;
use warnings;
use File::Find;
$| = 1;
my $TopDir = '/temp/sub';
find({wanted => \&wanted},$TopDir);
sub wanted {
if (-d $File::Find::name && $File::Find::name ne $TopDir) {
$File::Find:rune = 1 ;
return;
}
return if -d;
# Processing for the file goes here
print "file: $File::Find::name\n";
}
I would like to be have find() only traverse a top level directory
(controlling how deep to go would also be helpful).
This is the best I could do. This code breaks if a relative directory
path is specified. It seems that File::Find should provide a way to
specify the maximum depth but I could not find anything.
use strict ;
use warnings;
use File::Find;
$| = 1;
my $TopDir = '/temp/sub';
find({wanted => \&wanted},$TopDir);
sub wanted {
if (-d $File::Find::name && $File::Find::name ne $TopDir) {
$File::Find:rune = 1 ;
return;
}
return if -d;
# Processing for the file goes here
print "file: $File::Find::name\n";
}