A: Added examples.

This commit is contained in:
Jens Luedicke
2012-09-01 10:50:02 +02:00
parent 8ea37c6a8c
commit f643ad1551
2 changed files with 74 additions and 0 deletions

35
examples/find-perl-binary.pl Executable file
View File

@@ -0,0 +1,35 @@
#!/usr/bin/perl
use strict;
use warnings;
use File::Basename;
use File::DirWalk;
my $dw = new File::DirWalk();
$dw->onDirEnter(sub {
my ($path) = @_;
print "$path\n";
if (basename($path) =~ /sbin|lib|share|local|include|libexec|X11/) {
return PRUNE;
}
return SUCCESS;
});
$dw->onFile(sub {
my ($path) = @_;
print "$path\n";
if (basename($path) eq "perl") {
return ABORTED;
}
return SUCCESS;
});
$dw->walk("/usr");

39
examples/ls.pl Executable file
View File

@@ -0,0 +1,39 @@
#!/usr/bin/perl
use strict;
use warnings;
use Cwd;
use File::Basename;
use File::DirWalk;
my $dw = new File::DirWalk();
my $size = 0;
$dw->setDepth(1);
$dw->onBeginWalk(sub {
my ($path) = @_;
if ($dw->filesInDir() > 0) {
print $dw->currentBasename() . "\n";
$size += -s $path;
}
return SUCCESS;
});
$dw->onDirLeave(sub {
print $dw->filesInDir(), " files ($size bytes)\n";
return SUCCESS;
});
if (-e $ARGV[0]) {
$dw->walk($ARGV[0]);
} else {
my $cwd = getcwd();
$dw->walk($cwd);
}