How to remove SVN metadata using PowerShell

Recently I decided to write a PowerShell script that will delete all directories named ".svn" from given directory and all subdirectories (which effectively removes all SVN metadata). On the Stack Overflow website I've found a command which will do what I need:

Get-ChildItem $path -Recurse -Force *.svn |
    Where {$_.PSIsContainer} | Remove-Item -Recurse -Force

And what turned out? The result of its execution is correct, but PowerShell displays ugly error messages by the way:

PowerShell: Remove-SvnMetadata

To get rid of these errors, I recommend using two subsequent commands:

$itemsToRemove = Get-ChildItem $path -Recurse -Force .svn |
    Where {$_.PSIsContainer}
$itemsToRemove | Remove-Item -Recurse -Force

Of course, these commands can be put into a script file which will take the directory path as a parameter. To do this, you should create a file named for example Remove-SvnMetadata.ps1 with the following content:

$itemsToRemove = Get-ChildItem $args[0] -Recurse -Force .svn |
    Where {$_.PSIsContainer}
$itemsToRemove | Remove-Item -Recurse -Force

To use the script, you should place it in a directory that is present in your PATH environment variable (I use C:\Users\BlaSOFT\scripts) or just in PowerShell console go to directory containing the script (then before the script name you should put .\). This is an example call which will remove all SVN metadata from D:\Temp\20110507 directory and all its subdirectories:

Remove-SvnMetadata.ps1 D:\Temp\20110507

I would like to say that I am also aware of the existance of Export function in SVN (svn export), but the solution I presented allows us to do the task even if we don't have any SVN client available in the system (or we don't want to use SVN for some reason).

Add comment

  Country flag

biuquote
  • Comment
  • Preview
Loading