#!/usr/bin/perl # linux only, use appropriate \ for MSWindows use warnings; use File::Find; use File::Spec; use Cwd; my $total_count; my $pwd = getcwd; my $count = ($pwd =~ tr/\///); if (@ARGV < 2){print "Usage: $0 dir depth\n";exit} my ($path, $depth)= @ARGV; my $abs_path = File::Spec->rel2abs($path); #in case you enter . for dir #count slashes in top path my $m = ($abs_path) =~ tr!/!!; find (\&found,$abs_path); print "\n\nTOTAL: $total_count\n"; exit; sub found { my $n = ($File::Find::name) =~ tr!/!!; #count slashes in file return $File::Find::prune = 1 if $n > ($m + $depth); return unless -d; # do stuff here. my $count_here = ($File::Find::name =~ tr/\///); if ($count_here eq $count+2) { print "$_\n"; $total_count++; #name only } }