1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
#! /usr/bin/perl use strict; use warnings; use feature qw(say); use File::Find; use Cwd; my $name = shift; my $basedir = shift; exit 1 unless defined $name; $basedir = getcwd unless defined $basedir; die "'$basedir' is not a directory.\n" unless -d $basedir; # print full path if it is a directory and the last part matches $name find( sub { say $File::Find::name if -d $File::Find::name && $_ eq $name }, $basedir );
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
use File::Find; my @ordner_in_denen_gesucht_werden_soll=( '/nur/ein/test/', '/ein/ganz/anderer/ort', ); my $zu_findender_ordner_name='ein_name'; my @liste_aller_pfade_die_mit_dem_passenden_name_enden=(); find \&funktion_die_auf_jeden_pfad_angewendet_wird, @ordner_in_denen_gesucht_werden_soll; sub funktion_die_auf_jeden_pfad_angewendet_wird { my $aktueller_pfad=$File::Find::name; my $aktueller_name=$_; return unless(-d $aktueller_pfad); if($aktueller_name eq $zu_findender_ordner_name) { push @liste_aller_pfade_die_mit_dem_passenden_name_enden, $aktueller_pfad; } } for my $pfad (@liste_aller_pfade_die_mit_dem_passenden_name_enden) { print "$pfad\n"; }
1
2
3
4
5
6
7
8
9
10
11
12
use File::Find::Rule;
my @start = qw(
/start1/
/path/start2/
);
my $dir_to_find = 'dirname';
my @dirs = File::Find::Rule->directory
->name( qr/\A\Q$dir_to_find\E\z/ )
->in( @start );
my @start = ( $Path );