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
sub recDir { my $f; my @theDir; my $DIR; my @theDir; system "pwd"; my @dfiles; @dfiles = glob("*.d"); foreach $f (@dfiles) { printf ("found $f \n"); } if (opendir ($DIR, ".")) { # print "+\n"; @theDir = readdir($DIR); foreach $f (@theDir) { unless ( ($f eq ".") || ($f eq "..") ) { # printf "-$f\n"; if (-d $f) { # printf "+$f\n"; chdir($f); recDir($f); chdir(".."); } } } } else { print "can't open Dir $sourcefile $! \n"; $globalerror = 1; } } chdir($ARGV[0]); recDir($ARGV[0]);
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
#!/usr/bin/perl use strict; use warnings; use File::Find; my $globalerror=0; sub recDir { my $path=shift(@_); find(sub{ my $file=$File::Find::name; if($file=~/\.d$/) { if(open(my $fh, '<', $file)) { local $/=undef; print <$fh>; close($fh); } else { warn "Can't open $file ($!)\n"; $globalerror = 1; } } },$path); } recDir($ARGV[0]);
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
#!/usr/bin/perl use strict; use warnings; my $globalerror=0; sub recDir { my $path=shift(@_); if (opendir (my $DIR, $path)) { my @files=readdir($DIR); closedir($DIR); for my $file (@files) { # . und .. überspringen next if($file eq '.' or $file eq '..'); # pfad konstruieren my $new_path="$path/$file"; # wenn Datei und Endung ".d" if(-f $new_path and $file=~/\.d$/) { # Datei öffnen und ausgeben if(open(my $fh, '<', $new_path)) { local $/=undef; print <$fh>; close($fh); } else { warn "Can't open $new_path ($!)\n"; $globalerror = 1; } } recDir($new_path) if (-d $new_path); } } else { warn "can't open Dir $path ($!)\n"; $globalerror = 1; } } recDir($ARGV[0]);