Thread selektives File::Find
(13 answers)
Opened by lichtkind at 2013-07-04 22:04
Mein Beispiel nochmal in zwei Funktionen (statt in einer):
Code (perl): (dl
)
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()); |