Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I need to remove all files and folders from a particular parent folder except those which have .svn as the foldername and those which have *.svn-base as their filename.

Is there a Windows script that can do this for me?


@Mizo - your solution returned the following while wiping out everything:

File not found - *.svn_base
0 File(s) copied
0 File(s) copied

I had changed the clean.bat reference in the file itself.


I fixed the typo as follows but still the same error

XCOPY /Q /Y *.svn-base __cltmp

File not found - *.svn-base
0 File(s) copied
0 File(s) copied


(a) It keeps prompting me

The item at C:\temp\f\a\d has children and the Recurse parameter was not specified. If you continue,
all children will be removed with the item. Are you sure you want to continue?
[Y] Yes  [A] Yes to All  [N] No  [L] No to All  [S] Suspend  [?] Help (default is "Y"): 

(b) It displays THOUSANDS of messages like:

At line:1 char:86
+ get-childitem C:\temp\ -exclude *.svn-base,".svn" -recurse | foreach ($_) {remove-item <<<<  $_.fullname}
    + CategoryInfo          : PermissionDenied: (change_email.php.svn-base:FileInfo) [Remove-Item], IOException
    + FullyQualifiedErrorId : RemoveFileSystemItemUnAuthorizedAccess,Microsoft.PowerShell.Commands.RemoveItemCommand
Remove-Item : Cannot remove item C:\temp\admin\.svn\text-base\change_email_submit.php.svn-base: Not Enough permission to
 perform operation.
share|improve this question
up vote 0 down vote accepted

Using Powershell:

get-childitem C:\folder\ -exclude *.svn-base,".svn" -recurse | foreach ($_) {remove-item $_.fullname}

Update: the code below should do what you wanted. It removes all files except *.svn-base AND does not delete ANY folders.

Some notes:gci is an alias of get-childitem, just to save some space. Added -Force parameter to remove-item since you seem to have some kind of permissions problem.

gci C:\folder\ -exclude *.svn-base -recurse | foreach ($_) {if(!$_.PSIsContainer){remove-item -Force $_.fullname}}
share|improve this answer
@Siim - I didnt realize I had powershell installed. I am trying this solution and it does seem to be working, but it seems to be taking longer than operating through the Windows explorer interface!! (see Edit3 as well) – siliconpi Jan 20 '11 at 23:12
@Siim - one problem (which I see I didnt specify the question correctly) is that your solution removes folders as well. I actually do not need any subfolders removed, whether they are .svn or otherwise. How can I modify this script to do that? – siliconpi Jan 21 '11 at 2:50
@matt_tm I've updated the code, pls check – Siim K Jan 21 '11 at 9:47
@Siim - I ended up using a variation of the concept - get-childitem C:\temp\ -exclude *.svn-base,".svn" -recurse | foreach ($_) { if ($_.Attributes -ne "Directory") {remove-item -Force $_.fullname} } – siliconpi Jan 21 '11 at 10:02
@Siim - thank you for introducing me to the concept of powershell! Wasn't aware of it before! – siliconpi Jan 21 '11 at 10:02


FOR /F "tokens=*" %%d IN ('dir /B /AD') DO IF NOT %%d==.svn RMDIR /S /Q %%d
MD __cltmp
XCOPY /Q /Y *.svn_base __cltmp
FOR /F "tokens=*" %%f IN ('dir /B /A-D') DO IF NOT %%f==clean.bat DEL /F /Q %%f
XCOPY /Q /Y __cltmp\* .
RMDIR /S /Q __cltmp
share|improve this answer
@mizo - please see edit1 – siliconpi Jan 20 '11 at 15:41
@mizo - please see edit2 as well – siliconpi Jan 20 '11 at 20:41
@mizo - Issue1: this doesn't get into subfolders at all! – siliconpi Jan 20 '11 at 21:40
@matt_tm, no, it wipes out all subfolders whose name is not .svn. Do you need it to be recursive? – mizo Jan 20 '11 at 21:42
Issue2: The first FOR /F statement matches .svn folders anyway... I want to exclude all data which is within a .svn folder! – siliconpi Jan 20 '11 at 21:42

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .