How would one go about deleting all Subversion files from a directory using PowerShell?
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.
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…
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.
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”.
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 ?
.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With