Skip to content

Instantly share code, notes, and snippets.

@dirkstoop
Created March 15, 2011 18:37
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dirkstoop/871204 to your computer and use it in GitHub Desktop.
Save dirkstoop/871204 to your computer and use it in GitHub Desktop.
Recursively clear those pesky .svn folders from a directory
#!/usr/bin/env python
#
# clearsvnentries.py
# scripts
#
# Created by Dirk on 2009-06-03.
# Copyright 2009 Sofa BV. Use for good, not bad.
#
import os
import sys
import shutil
def clearpath(targetPath, silent=False):
currentWorkingDirectory = os.getcwd()
os.chdir(targetPath)
found = 0
for directoryPath, directoryNames, fileNames in os.walk('.'):
for directoryName in directoryNames:
if directoryName == u'.svn':
path = os.path.abspath(os.path.join(directoryPath, directoryName))
if os.path.isdir(path):
found += 1
if not silent:
print u'Removing \'%s\'' % (path)
shutil.rmtree(path)
os.chdir(currentWorkingDirectory)
if not silent:
if not found:
print 'No .svn metadata found in \'%s\'.' % (os.path.abspath(targetPath))
else:
print 'Deleted %i .svn folder%s in \'%s\'.' % (found, ([c for c in 's' if found>1] or [''])[0], os.path.abspath(targetPath))
if __name__ == '__main__':
if len(sys.argv) >= 2:
targetPath = sys.argv[len(sys.argv)-1]
silent = u'-s' in sys.argv or u'--silent' in sys.argv
clearpath(targetPath, silent=silent)
else:
fileName = os.path.split(__file__)[1]
print 'Clears .svn metadate from directories recursively.\nUsage: %s <path>\noption: -s or --silent to print no output' % (fileName)
sys.exit()
@dirkstoop
Copy link
Author

save this as a file somewhere in your PATH, make it executable and tadaa, a oneliner to clear .svn folders

@dirkstoop
Copy link
Author

And yes, I realize you can do this with "find" and a couple more shell commands piped together, but I can never (a) remember that one-liner, or (b) get that it work reliably with non-ascii filenames, or filenames with spaces in them.

@rareyman
Copy link

Awesome. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment