Advertisement
Guest User

Untitled

a guest
Sep 30th, 2014
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.26 KB | None | 0 0
  1. sub wanted {
  2. # $_ set to filename; $File::Find::name set to full path.
  3. if ( m/.rcZ/ ) {
  4. print "Removing $File::Find::namen";
  5. unlink ( $File::Find::name );
  6. }
  7. }
  8.  
  9. sub wanted { /.rc$/ && ( unlink $File::Find::name or die "Unable to delete $_: $!" ) }
  10.  
  11. `$File::Find::dir` is the current directory name,
  12.  
  13. `$_` is the current filename within that directory
  14.  
  15. `$File::Find::name` is the complete pathname to the file.
  16.  
  17. my $dir = "$targetRoot\20140929_231622";
  18. #subroutine call
  19. wanted($dir);
  20.  
  21. #subroutine declaration
  22. sub wanted
  23. {
  24. my $result = $_[0];
  25.  
  26. my @p = grep {-f} glob("$result\*.rc");
  27. foreach my $file (@p)
  28. {
  29. print "Removing files $file from the directory $dir" . unlink($file) . "n";
  30.  
  31. }
  32. }
  33.  
  34. #!/usr/bin/env perl
  35.  
  36. use strict;
  37. use warnings;
  38.  
  39. use Path::Class;
  40.  
  41. run(@ARGV ? @ARGV : ['.']);
  42.  
  43. sub run {
  44. my $argv = shift;
  45. my $dir = dir(shift @$argv)->resolve; # will croak if path does not exist
  46. $dir->recurse(callback => &rm_if_rcfile);
  47. return;
  48. }
  49.  
  50. sub rm_if_rcfile {
  51. my $entity = shift;
  52. return if $entity->is_dir;
  53. return unless $entity =~ / [.] rc z/ix;
  54. print "$entityn";
  55. return; # remove this line to actually delete
  56. unless ($entity->remove) {
  57. warn "'$entity' failed: $!n";
  58. }
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement