views:

287

answers:

6

Hello,

I want to be able to remove the .SVN folders from a directory.

I found the following registry hack that will allow you to do just that...

http://weblogs.asp.net/jgalloway/archive/2007/02/24/shell-command-remove-svn-folders.aspx

However, the one thing I don't like about this solution is that it gives NO CONFIRMATION at all. I would like it to do what this cmd script does but get a confirmation prompt first.

Any ideas at all?

EDIT My understanding is that SVN Export does not copy out the unversioned files. That is why I ask for this.

Seth

+4  A: 

You can use the Subversion command line and run svn export If you are using TortoiseSVN, you can use this.

larrys
Larry, great answer. I DO use TortoiseSVN. I was aware of the svn Export command. My understanding is that SVN Export does not copy the unversioned files. That is why I was asking (and should have made clearer in the question). That said I was not aware of the Tortoise feature. Does that leave unversioned files intact?
Seth Spearman
I've not had a need to do this, so I wouldn't know. One way to find out is to try it out in your environment with a test working copy.
larrys
If you select **Export All**, it will include unversioned files.
RedFilter
A: 

Remove the /q option on the RD command buried in that script.

That should cause each invocation of rd (remove directory) to ask...

At the same time, though, I'd ask why you don't use the svn export option instead.

SuperMagic
A: 

If you use Perl at all, here's a little script I have for doing this, plus taking out other dir types (handy for /bin, etc.. from VS):

#!/usr/local/bin/perl -w
#-------------------------------------------------------------------------------
# removedirs.pl - Recursively removes directories from a given root folder
# Author: Nick Gotch
# Date: 07-13-2009
#-------------------------------------------------------------------------------
use strict;
use warnings;
use File::Path;

#-------------------------------------------------------------------------------
# User Setting Variables
#-------------------------------------------------------------------------------
my $basepath = 'C:\\Path\\to\\RootDir\\';

#-------------------------------------------------------------------------------
# Processing
#-------------------------------------------------------------------------------
# Prompt for Confirmation
syswrite(STDOUT, "Confirm removal of directories?\nPress 'Y' to confirm.\n");
$confirm = <STDIN>;
if($confirm =~ /^[Yy]$/)
{
    # Add lines here to remove other dirs...
    RemoveDir($basepath, ".svn");
    syswrite(STDOUT, "Done.\nPress <ENTER> to close.\n");
}
<STDIN>;

sub RemoveDir
{
    my ($directory, $dirtodelete) = @_;

    if(-e $directory.'\\'.$dirtodelete.'\\')
    {
        rmtree($directory.$dirtodelete.'\\');
        syswrite(STDOUT, "Removed: ".$directory.$dirtodelete.'\\'."\n");
    }

    opendir(DIR, $directory);
    my @subdirlist;

    while(my $subdir = readdir(DIR))
    {
        if(($subdir ne '.') && ($subdir ne '..') && (-d $directory.$subdir))
        {
            push(@subdirlist, $directory.$subdir.'\\');
        }
    }

    closedir(DIR);

    foreach my $subdir (@subdirlist) { RemoveDir($subdir, $dirtodelete); }
}
Nick Gotch
A: 

What if you put content of the script to the cmd file and then set registry so that it points to this cmd file? Then you could add various actions like in the examples at Wikipedia. I hope this helps you to create a solution.

Tx3
+1  A: 

Try this modification of the script. It adds a single prompt before running the directory deletions:

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Folder\shell\DeleteSVN]
@="Delete SVN Folders"

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Folder\shell\DeleteSVN\command]
@="cmd.exe /c \"TITLE Removing SVN Folders in %1 && COLOR 9A && choice /m "Remove SVN folder" && if ERRORLEVEL 2 goto done && FOR /r \"%1\" %%f IN (.svn) DO RD /s /q \"%%f\" && :done \""
RedFilter
This did not work. Just ran without prompting. I like the idea though. This is just what I want.
Seth Spearman
Gimme a sec, I'll test it out...
RedFilter
The syntax seems highly dependent on the version of Windows you are running so I have given up... :)
RedFilter
A: 

Try this for the Powershell command for the reg value:

C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -Command "& {if ((read-host 'Confirm deletion of .SVN folder. Press Y or N') -eq 'y') { Get-ChildItem '%1' -r *.svn | ?{$_.PSIsContainer} | Remove-Item -r -force -verbose -ea 0; Read-Host 'Press enter to exit' }}"

Remove the -verbose if you don't want to see the files deleted.

Keith Hill