Posted By


FazzyX on 04/08/11

Tagged


Statistics


Viewed 858 times
Favorited by 0 user(s)

SearchAndDestroy


/ Published in: Perl
Save to your folder(s)

Recursive delete of given file or folder, e.g. .svn folder
Call : [Program] [SearchPath] [DeleteItem]


Copy this code and paste it in your HTML
  1. #!/usr/bin/perl
  2. use strict;
  3.  
  4. use File::Find;
  5. use File::Path;
  6. use Digest::MD5 qw{md5_hex};
  7.  
  8. if(!($ARGV[0] && $ARGV[1])){
  9. print "Keine oder nicht genuegend Parameter mitgegeben, Programm wird beendet.\n";
  10. print "Aufruf : <Program> <SearchPath> <DeleteItem>...\n";
  11. }
  12.  
  13. (my $startToSearchDir, my $deleteItem) = @ARGV;
  14.  
  15. find(\&wanted, $startToSearchDir);
  16.  
  17. sub wanted {
  18. if($_ eq $deleteItem){
  19. if(-d $File::Find::name) {
  20. print "Deleting : " . $deleteItem . "\n";
  21. rmtree($deleteItem);
  22. } else {
  23. print "Deleting : " . $deleteItem . "\n";
  24. unlink($deleteItem);
  25. }
  26. }
  27. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.