tags:

views:

250

answers:

1

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)

+11  A: 

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;
}
Sinan Ünür
Does Path::Class come with standard installations?
PP
No. But you can use `File::Spec` instead.
Sinan Ünür
Great! thanks. For some reason I had to switch remove_tree with rmtree(), but after that it worked great.
Lucas Meijer
The docs say *The rmtree() function provide the legacy interface of remove_tree() with a different interpretation of the arguments passed.* I am not sure what that means. I updated the posted solution to use `rmtree`. Also, now the script will do the right thing when no or multiple top directories are specified on the command line.
Sinan Ünür
@PP You know it is highly annoying that you keep posting comments about me deriding you. For the record, I did not vote down your answer (now deleted). I pointed out that it was unnecessary to do all that work. Your revenge downvoting of my answer is amusing but also very much uncalled for.
Sinan Ünür