# this subroutine will take path and use File::Find to decend # one directory level deeper and list the directories it finds there # if it encounters a 'home', 'shared', or 'expansions' directory it'll # descend [even] one level deeper than otherwise sub go_deeper { #arguments 1) unc style path string i.e. '\\fileshare1\froot$' #returns 1) array with paths to directories below the given path # find directories my $path_line = shift; chomp($path_line); # delete trailing backslash if its there if ( substr( $path_line, -1 ) eq '\\' ) { substr( $path_line, -1 ) = ''; } our $depth = 0; our $original_depth = $depth; our @dirs_list = (); find( { preprocess => \&preprocess, wanted => \&wanted }, $path_line ); sub wanted { my $dir = $File::Find::name; print LOG "DEBUG Entered wanted function. CWD: $dir \n"; if ( ( index( lc($dir), 'home' ) != -1 || index( lc($dir), 'expansion' ) != -1 || index( lc($dir), 'share' ) != -1 ) and $depth == $original_depth ) { print LOG "DEBUG adding to depth\n"; $depth++; } elsif ( $depth != $original_depth ) { print LOG "DEBUG subtracting from depth\n"; $depth--; } my $depth_count = $File::Find::dir =~ tr[/][]; # count slashes to get depth return if $depth_count < $depth; if ( (-d) && ( $_ ne '.' ) ) { $dir =~ s/\//\\/g; print LOG "DEBUG Adding dir to file: " . $dir . "\n"; push( @dirs_list, $dir ); } } sub preprocess { my $depth_count = $File::Find::dir =~ tr[/][]; return @_ if $depth < $depth; if ( $depth_count == $depth ) { return grep { -d } @_; } return; } return @dirs_list; }