Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I recursively delete all .svn directories using Perl?

Tags:

perl

What would a Perl script look like that would take a directory, and then delete all .svn directories in that directory recursively?

(No shell, cross platform)

like image 441
Lucas Meijer Avatar asked Dec 10 '22 18:12

Lucas Meijer


1 Answers

You can (and probably should) use svn export in the first place.

Otherwise, use File::Find and File::Path::rmtree:

#!/usr/bin/perl

use strict; use warnings;

use File::Find;
use File::Path qw( rmtree );
use File::Spec::Functions qw( catfile );

find(\&rm_dot_svn, $_) for @ARGV;

sub rm_dot_svn {
    return unless -d $File::Find::name;
    return if /^\.svn\z/;
    rmtree(catfile $File::Find::name, '.svn');
    return;
}
like image 70
Sinan Ünür Avatar answered Dec 12 '22 07:12

Sinan Ünür