Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to recursively delete all SVN files using PowerShell

Tags:

powershell

svn

How would one go about deleting all Subversion files from a directory using PowerShell?

like image 310
epitka Avatar asked Feb 05 '10 20:02

epitka


People also ask

How do I delete all recursively from SVN?

The find command returns a list of all the subfolders matching “. svn”, and this is then piped to the rm command to recursively delete the directory. Running rm using the full path will remove the confirmation prompt, and the “rf” arguments will recursively delete any folder contents.

How do I delete everything from SVN?

To remove a file from a Subversion repository, change to the directory with its working copy and run the following command: svn delete file… Similarly, to remove a directory and all files that are in it, type: svn delete directory…

How do you recursively delete a file in PowerShell?

Using PowerShell to Delete All Files Recursively If you need to also delete the files inside every sub-directory, you need to add the -Recurse switch to the Get-ChildItem cmdlet to get all files recursively.

How do I remove all files from a directory in PowerShell?

Every object in PowerShell has a Delete() method and you can use it to remove that object. To delete files and folders, use the Get-ChildItem command and use the Delete() method on the output. Here, this command will delete a file called “testdata. txt”.


3 Answers

If you really do want to just delete the .svn directories, this could help:

gci c:\yourdirectory -include .svn -Recurse -Force | 
   Remove-Item -Recurse -Force

Edit: Added -Force param to gci to list hidden directories and shortened the code.

Keith is right that it you need to avoid deleting files with .svn extension, you should filter the items using ?.

like image 100
stej Avatar answered Oct 07 '22 12:10

stej


Assuming you don't want to delete any files that might also have .svn extension:

Get-ChildItem $path -r -include .svn -Force | Where {$_.PSIsContainer} |
    Remove-Item -r -force

Microsoft has responded to the suggestion in the comments below that Keith opened on MS Connect! As of PowerShell V3 you can do away with the extra (very slow) pipe to Where {$_.PSIsContainer} and use -directory instead:

gci $path -r -include .svn -force -directory | Remove-Item -r -force

PowerShell v3 can be downloaded for Windows 7 at Windows Management Framework 3.0.

like image 32
Keith Hill Avatar answered Oct 07 '22 14:10

Keith Hill


How about using SVN Export to get a clean checkout without .svn directories?

Edit

You might want to look at the answer here:

Command line to delete matching files and directories recursively

like image 5
Sofahamster Avatar answered Oct 07 '22 13:10

Sofahamster