preprocess => sub { .. }
1 2 3 4 5
my $wanted = sub { if($File::Find::dir ne 'kaputtes dir') { ...ablauf... } }
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
$ ls -l
insgesamt 96
drwxr-xr-x 4 ebook ebook 4096 2013-07-05 11:43 .
drwxr-xr-x 4 root root 4096 2013-01-04 00:56 ..
-rw-r--r-- 1 ebook ebook 179 2010-09-15 13:41 examples.desktop
-rwxrwxrwx 1 ebook ebook 79173 2013-01-15 10:49 perlybook.log
drw------- 2 ebook ebook 4096 2013-07-05 11:43 test
drwxrwxrwx 4 ebook ebook 4096 2013-01-15 01:06 tmp
$ perl -E 'say -r "test"'
$ perl -E 'say -r "tmp"'
1
$ whoami
hugo
$
Can't opendir(/.Trashes): Permission denied
1 2 3 4 5 6 7
# IN ALL CASES: we list the available directories # in "data" (level 1, not hidden, not archived) my @dirs = File::Find::Rule->directory ->maxdepth(1) ->not_name('.*') ->not_name('_*') ->in($place_to_store);
2013-07-06T20:28:34 lichtkindweil bekomm ich manuell was schnelleres.
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 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
#!/usr/bin/perl use warnings; use strict; # myfind.pl use Cwd; sub myfind { my $wd = shift; opendir(DIR, $wd); my @dirs = (); while(my $fname = readdir(DIR)) { if ($fname eq "." || $fname eq "..") { next; } my $fullfname = "$wd/$fname"; if (-d $fullfname) { push(@dirs, $fullfname); } } close(DIR); foreach my $adir (@dirs) { print "$adir\n"; # Printing files inside directories: opendir(ADIR, $adir); while(my $afile = readdir(ADIR)) { if ($afile eq "." || $afile eq "..") { next; } print "$afile\n"; } close(ADIR); print "\n"; myfind($adir); } } myfind(getcwd());
2013-07-06T20:54:30 hlubenowWenn ich mich nicht irre, folgt aus der Rekursion auch, daß man nicht ohne weiteres Verzeichnisbäume ausschließen kann.
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 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
#!/usr/bin/perl use strict; use warnings; my @files; my @ignore=( '/usr/bin/', '/home', ); iterate_dirs( # entscheiden ob das Verzeichnis besucht werden soll sub{ for(@ignore) { return 0 if( index($_[1],$_)==0 ); } return 1 if( -r $_[0] ); return 0; }, # Auswerten des Eintrags sub{ push(@files, $_[1]) if( -f $_[0] and -r $_[0] and substr($_[0],-4,4) eq '.pod' ); }, # die zu durchsuchenden Verzeichnisse '/usr/lib/perl5' ); print "$_\n" for( @files ); ################################# sub iterate_dirs { my ($decide_code, $each_code, @stack ) =@_ ; my $dir=getcwd; my ($p,$dh,$path,$tmp); while(@stack) { $path = pop(@stack); chdir( $path ) or die "chdir($path) failed: $!";; opendir( $dh, '.' ) or die "Unable to open $path: $!\n"; for( readdir( $dh ) ) { next if( $_ eq '.' or $_ eq '..' ); $tmp=$path.'/'.$_; push(@stack, $tmp) if( -d $_ and $decide_code->( $_, $tmp ) ); $each_code->( $_, $tmp ); } closedir ($dh); } chdir ( $dir ) or die "chdir($dir) failed: $!\n"; return 1; }
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 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
#!/usr/bin/perl use warnings; use strict; # myfind.pl use Cwd; sub myfind { my $wd = shift; my @dirs = listdir($wd, "dirs", "fullname"); foreach my $adir (@dirs) { print "$adir\n"; # Printing files inside directories: my @fnames = listdir($adir, "all", "localname"); foreach my $afile (@fnames) { print "$afile\n"; } print "\n"; myfind($adir); } } sub listdir { my $dir = shift; my $select = shift; my $basename = shift; my $filename; my @files; opendir(DIR, $dir) or die; while($filename = readdir(DIR)) { next if ($filename eq "." || $filename eq ".."); my $fullfname = "$dir/$filename"; next if ($select eq "dirs" && ! -d $fullfname); if ($basename eq "fullname") { push(@files, $fullfname); } else { push(@files, $filename); } } close(DIR); return @files; } myfind(getcwd());