Skip to content

Instantly share code, notes, and snippets.

@dgrant
Created May 2, 2015 05:12
Show Gist options
  • Save dgrant/26341c2b2fdc74594d04 to your computer and use it in GitHub Desktop.
Save dgrant/26341c2b2fdc74594d04 to your computer and use it in GitHub Desktop.
Remove non .svn dirs
#!/usr/bin/env python
"""Remove all directories except .svn directories"""
import os
def remove_non_dot_svn_dirs(root):
"""Remove all directories except .svn directories under too"""
for dirpath, _, files in os.walk(root):
if dirpath.find('.svn') == -1:
for afile in files:
fullpath = os.path.join(dirpath, afile)
print "Removing", fullpath
os.remove(fullpath)
def main():
"""Main function that handles all command line parsing"""
from optparse import OptionParser
usage = "usage: %prog [options] directory"
parser = OptionParser(usage)
_, args = parser.parse_args()
if len(args) < 1:
parser.error("A directory must be specified")
remove_non_dot_svn_dirs(args[0])
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment