------------------------------------------------------------------------------- File::Find Module Note that Find:File always handles files and directories separately, typically all the files first, then all the directories, though each group is in the order in which the user sorted them. No option is provided to traverse both files and directories in either, the order they are sorted into. ------------------------------------------------------------------------------- Basic Find File Script and notes. =======8<--------CUT HERE----------axes/crowbars permitted--------------- use $File::Find; my %find_opts = ( preprocess => \&sort_dir, # sort the contents of a directory postprocess => \&end_dir, # just mark the end of a recursive step wanted => \&do_files, # process each item in directory ); my $recurse = 1, shift if $1 eq "-r"; File::Find::find(\%find_opts, "$1" ); exit 0; sub sort_dir { # preprocess # this is called after the directory contents have been read # with a list of the filenames from that direcory (order?) # print "Traverse: $File::Find::dir (", scalar @_, ")\n"; if ( $File::Find::dir eq "/...../this_dir" ) { return; # This prunes all sub-files and sub-dirs from search, # but only AFTER the directory was passed to the # "wanted=\&do_files" sub-routine; } return ( sort @_ ); # Sort filenames. #return ( sort { $b cmp $a } @_ ); # Sort filenames in reverse order #return ( sort { $a <=> $b } @_ ); # Sort filenames numerically #return ( @_ ); # Don't Sort filenames. } sub end_dir { # postprocess print " <---: $File::Find::dir\n"; } sub do_files { if ( -d $_ && $File::Find::dir eq "/...../that_dir" ) { $File::Find::prune = 1; # Removes directory from search, # The directory is NOT read, and the # "preprocess=\&sort_dir" is not called } if ( -d $_ ) { # effective way to stop recursion beyond $File::Find::prune = $sub_dir; # the sub-directory that was given to $sub_dir=!$recurse; # look at. } # print "\t$_\n"; # just the name printf "\t%-4s $_\n", # name and file type -d $_ ? "DIR" : -f _ ? "FILE" : "???"; # printf "\t%-4s $File::Find::name\n", # full file path # -d $_ ? "DIR" : -f _ ? "FILE" : "???"; } =======8<--------CUT HERE----------axes/crowbars permitted---------------