Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- sub wanted {
- # $_ set to filename; $File::Find::name set to full path.
- if ( m/.rcZ/ ) {
- print "Removing $File::Find::namen";
- unlink ( $File::Find::name );
- }
- }
- sub wanted { /.rc$/ && ( unlink $File::Find::name or die "Unable to delete $_: $!" ) }
- `$File::Find::dir` is the current directory name,
- `$_` is the current filename within that directory
- `$File::Find::name` is the complete pathname to the file.
- my $dir = "$targetRoot\20140929_231622";
- #subroutine call
- wanted($dir);
- #subroutine declaration
- sub wanted
- {
- my $result = $_[0];
- my @p = grep {-f} glob("$result\*.rc");
- foreach my $file (@p)
- {
- print "Removing files $file from the directory $dir" . unlink($file) . "n";
- }
- }
- #!/usr/bin/env perl
- use strict;
- use warnings;
- use Path::Class;
- run(@ARGV ? @ARGV : ['.']);
- sub run {
- my $argv = shift;
- my $dir = dir(shift @$argv)->resolve; # will croak if path does not exist
- $dir->recurse(callback => &rm_if_rcfile);
- return;
- }
- sub rm_if_rcfile {
- my $entity = shift;
- return if $entity->is_dir;
- return unless $entity =~ / [.] rc z/ix;
- print "$entityn";
- return; # remove this line to actually delete
- unless ($entity->remove) {
- warn "'$entity' failed: $!n";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement